note 39851 added to control-structures

From: Date: Thu, 12 Feb 2004 22:12:55 +0000
Subject: note 39851 added to control-structures
Groups: php.notes 
Request: Send a blank email to php-notes+get-65070@lists.php.net to get a copy of this message
I notice when your inside a while loop the following wont evaluate as expected.. $query = " some query"; $result= db_query($db,$query); while( $data=$result->fetchRow() ){ if ($data['somevar'] = "2" ) { $answ = "value1"; } else { $answ = "value2"; } echo '<tr> <td>'.$answ.'</nobr></td> </tr>'; it will only display 'Value1' for all records returned, which means only the first if statement is getting evaluated however if you use.. $query = " some query"; $result= db_query($db,$query); while( $data=$result->fetchRow() ){ $answ = ( $data['somevar'] == 1) ? "Value1" : "Value2"; echo '<tr> <td>'.$answ.'</nobr></td> </tr>'; it will display all values accordingly for each row. ---- Manual Page -- http://www.php.net/manual/en/control-structures.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39851 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39851&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39851&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65070) next »