Welcome Guest, Not a member yet? Register   Sign In
Model Code error
#1

[eluser]stuffradio[/eluser]
Do you see anything wrong with this function? I can't seem to find anything wrong with it but it's not doing anything.

Code:
function updateTheTeam()
    {
        if ($this->round == 1):
                      $data = array(
                      'course' => $this->course,
                      'rd1' => $this->rd1,
                      'celebScore' => $this->celebScore,
                      'thru' => $this->thru
                      );
        
        $this->db->where('teamID', $this->teamID);
        $this->db->update('teams', $data);
        
        elseif ($this->round == 2):
        $data = array(
                      'course' => $this->course,
                      'rd2' => $this->rd2,
                      'celebScore' => $this->celebScore,
                      'thru' => $this->thru
                      );
        $this->db->where('teamID', $this->teamID);
        $this->db->update('teams', $data);    
        
        elseif ($this->round == 3):
        $data = array(
                      'course' => $this->course,
                      'rd3' => $this->rd3,
                      'celebScore' => $this->celebScore,
                      'thru' => $this->thru
                      );
        $this->db->where('teamID', $this->teamID);
        $this->db->update('teams', $data);    
        
        elseif ($this->round == 4):
        $data = array(
                      'course' => $this->course,
                      'rd4' => $this->rd4,
                      'celebScore' => $this->celebScore,
                      'thru' => $this->thru
                      );
        $this->db->where('teamID', $this->teamID);
        $this->db->update('teams', $data);
        
        endif;
    }
#2

[eluser]Michael Wales[/eluser]
Maybe the round property doesn't fit any of the conditionals? Add an else in there and echo out the value of the round property to see if it's not hitting any of them.
#3

[eluser]jdfwarrior[/eluser]
agreed... where is $this->round set?

Michael is right. It wouldnt do anything if the value didnt match anything. Have you confirmed that $this->round does in fact have a value when entering into that function?
#4

[eluser]stuffradio[/eluser]
I set $this->round in the controller that calls the model.
#5

[eluser]jdfwarrior[/eluser]
But still have you checked the value with the function to see what it's actually set to, to see if that's what it is, that it's not meeting criteria for the if statements?
#6

[eluser]Myles Wakeham[/eluser]
First thing I see that is wrong is a total lack of commenting in your code Sad
#7

[eluser]jdfwarrior[/eluser]
[quote author="Myles Wakeham" date="1235767566"]First thing I see that is wrong is a total lack of commenting in your code Sad[/quote]

hehe Smile
#8

[eluser]Michael Wales[/eluser]
Quote:First thing I see that is wrong is a total lack of commenting in your code Sad

Odd, first thing I saw was the alternative syntax for the conditionals (usually reserved for views).
#9

[eluser]GSV Sleeper Service[/eluser]
[url="http://uk3.php.net/manual/en/control-structures.switch.php"]switch![/url]
and you don't need all those repeating ->where()'s and ->update()'s, just have one at the end.
#10

[eluser]Evil Wizard[/eluser]
slightly more efficient and easier to follow i think
Code:
function updateTheTeam()
{
    $data = array(
        'course' => $this->course,
        'celebScore' => $this->celebScore,
        'thru' => $this->thru
        );
    switch($this->round):
        case 1:
            $data['rd1'] = $this->rd1;
        break;
        case 2:
            $data['rd2'] = $this->rd2;
        break;
        case 3:
            $data['rd3'] = $this->rd3;
        break;
        case 4:
            $data['rd4'] = $this->rd4;
        break;
    endswitch;
    $this->db->where('teamID', $this->teamID);
    $this->db->update('teams', $data);
}
but it all seems fine to me

is it actually being called?
and from where?




Theme © iAndrew 2016 - Forum software by © MyBB