XpertWorlock Posted June 24, 2008 Share Posted June 24, 2008 Hi, I have an if statement and it's not working right. The "else" is always displayed. while($row = mysql_fetch_array($result)) { $minusdate = (($dayday + $theday) - ($minusdayday + $minusday)); if ($minusdate == -1) { echo "<tr>"; echo "<td>"Hello "</td>"; echo "</tr>";} else { echo "<tr>"; echo "<td><a href=\"http://*********.org/wiki/Image:" . $row['img_name'] . "\" target=\"_blank\">" . $row['img_name'] . "</a></td>"; echo "<td>" . $row['img_size'] . "</td>"; echo "<td>" . $row['img_description'] . "</td>"; echo "<td>" . $row['img_timestamp'] . "</td>"; echo "<td>" . $minusdate . "</td>"; echo "</tr>"; } } the variable $minusdate is constantly being changed every time it loops (I have it in the html table working above) So if one time $minusdate == -1, shouldn't it display nothing and loop to the next row?? I'm doing something wrong obviously. No error's to help you guys with. PHP 5.25 Link to comment https://forums.phpfreaks.com/topic/111590-solved-if-statement-not-working-right/ Share on other sites More sharing options...
hitman6003 Posted June 24, 2008 Share Posted June 24, 2008 This should help you troubleshoot: while($row = mysql_fetch_array($result)) { $minusdate = (($dayday + $theday) - ($minusdayday + $minusday)); // debug... echo "Row with id " . $row['id'] . " has a minusdate of " . $minusdate . "<br />"; echo "Values were: ((" . $dayday . " + " . $theday . ") - (" . $minusdayday . " + " . $minusday . "))<br />"; echo str_repeat("-", 30) . "<br />"; if ($minusdate == -1) { echo ' <tr> <td>Hello </td> </tr>'; } else { echo ' <tr> <td> <a href=\"http://*********.org/wiki/Image:' . $row['img_name'] . '" target="_blank">' . $row['img_name'] . '</a> </td> <td>' . $row['img_size'] . '</td> <td>' . $row['img_description'] . '</td> <td>' . $row['img_timestamp'] . '</td> <td>' . $minusdate . '</td> </tr>'; } } Link to comment https://forums.phpfreaks.com/topic/111590-solved-if-statement-not-working-right/#findComment-572785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.