note 39851 deleted from control-structures by irchtml
| From: | irchtml@php.net | Date: | Fri, 13 Feb 2004 05:28:18 +0000 |
| Subject: | note 39851 deleted from control-structures by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65079@lists.php.net to get a copy of this message | ||
Note Submitter: dragoon@drug.org
----
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.