Jump to content


Photo

using a variable and making it keep track of changes


  • Please log in to reply
2 replies to this topic

#1 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 27 April 2006 - 02:18 PM

i dont know exactly what this is called but i do remember reading it somewhere.

i want use a variable, then if a condition is met add one to it. the way that i am trying to do is is while drawing a table. i have one cell that contains the variable

$no_waiver_count = 0;
...
$table .= "<tr><td colspan=\"4\">There are ". $$no_waiver_count ."...;

then there is a loop to draw the rest of the rows and inside of that loop is a condition and if it is met it will add one to the $no_waiver_count

if($index != -1){
$no_waiver_count++;
}

then when the loop is complete, i return $table. - i thought the double $$ would keep track of the changes but its not working, its only returning zero, when it should return 12.

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 27 April 2006 - 02:38 PM

[!--quoteo(post=369238:date=Apr 27 2006, 10:18 AM:name=emehrkay)--][div class=\'quotetop\']QUOTE(emehrkay @ Apr 27 2006, 10:18 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
i thought the double $$ would keep track of the changes but its not working, its only returning zero, when it should return 12.
[/quote]

you shouldn't need the double $$.

another example using a for loop

$var = 0;

for($i=0; $i<20; $i++){

if(condition){
$var = $var + 1;
}

}

echo $var;


"Confidence in the face of risk."

#3 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 27 April 2006 - 02:59 PM

[!--quoteo(post=369244:date=Apr 27 2006, 10:38 AM:name=micah1701)--][div class=\'quotetop\']QUOTE(micah1701 @ Apr 27 2006, 10:38 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you shouldn't need the double $$.

another example using a for loop

$var = 0;

for($i=0; $i<20; $i++){

if(condition){
$var = $var + 1;
}

}

echo $var;
[/quote]


the problem is that i want to use it before the loop and i want it to change depending on what is in the loop. here is my code, maybe you guys can see some errors in my thinking

edit i tried to change it to a class property, but it still doesnt work

<?
    public function draw_page_all(){
        
        $data = $this-> get_participant_list ($this->_work_unit);
        $count = count($data);
                
        $table = "<table>\n";
        
        if($count == 1 && ($data[0]->person_id == 0 ||  $data[0]->person_id == "")){
            
            $table .= "<tr><td colspan=\"4\">There are no participants at this time who have elected to share their ". APP_SHORT_NAME ." Course Transcripts.</td></tr>\n";
        
        }else{
        
            $table .= "<tr><td colspan=\"4\">There are ". $this->_no_waiver_count ." from who have elected that they do not wish to share their transcrips or have not yet agreed to the waiver.</td></tr>\n";
        
            for($i = 0; $i < $count; $i++){
                //check to see if participant signed the waiver
                
                $w = new WaiverDAO(); 
                $wArr = $w->getIncompleteWaivers(array(STI_ID, $data[$i]->person_id)); 
                $index = LMS_MISC::getIndex($wArr, 'waiver_id', 2); 
                
                if($index != -1){
                    $this->_no_waiver_count++;
                }else{
                    //display name and grab field info
                    $table .= "<tr><td colspan=\"4\">". $data[$i]->last_name .", ". $data[$i]->first_name ."</td></tr>\n";
                    $user_data = $this->get_data_user(STI_ID, $data[$i]->person_id);
                    $table .= $this->draw_page("all", $user_data);
                }                
            }
        }
        
    return    $table .= "</table>\n";
        
    }

}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users