leightr Posted July 1, 2007 Share Posted July 1, 2007 Can someone point out what is wrong with this? { if ($street == null) { echo 'No Directions'; } ELSE { echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; } } echo "</tr>"; It should say No Directions if $street is null. However it doesnt. It just echo's echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; instead. Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/ Share on other sites More sharing options...
sKunKbad Posted July 1, 2007 Share Posted July 1, 2007 try if(!isset($street)) instead Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287062 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 That did not work.. :'( Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287240 Share on other sites More sharing options...
AndyB Posted July 1, 2007 Share Posted July 1, 2007 That did not work.. :'( That isn't helpful. What do you mean? What do you mean by null - the string 'null', the value zero, and empty variable? How and where does $street get its value? Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287244 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 can you add var_dump before the <td><a href=directions.php?id=" .$row['id']. ">Map</td> and tell us what it displays.. will help us. var_dump($street); echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287255 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 Sorry. I forgot to paste the code ... Anyways, when I used isset nothing happened, it just did the same as the first code I pasted. Here is more of the code: $practice = mysql_query("SELECT * FROM schedules WHERE teamid='$username' AND gametype='Practice'"); echo "<h1>Scheduled Practice Games</h1>"; echo "<table border='1'> <tr> <th>Game Type</th> <th>Game Location</th> <th>Game Time</th> <th>Game Date</th> <th>Op. Team</th> <th>View Map</th> </tr>"; while($row = mysql_fetch_array($practice)) { echo "<tr>"; echo "<td>" . $row['gametype'] . "</td>"; echo "<td>" . $row['gamelocation'] . "</td>"; echo "<td>" . $row['gametime'] . "</td>"; echo "<td>" . $row['gamedate'] . "</td>"; echo "<td>" . $row['oppositeteam'] . "</td>"; // Lets see if there is a address to show a map link. $street = $row['street']; { if ($street == null) { echo 'No Directions'; } ELSE { echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; } } echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287281 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 I got string(4) "NULL" can you add var_dump before the <td><a href=directions.php?id=" .$row['id']. ">Map</td> and tell us what it displays.. will help us. var_dump($street); echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287283 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 change if ($street == null) { to if ($street == "NULL") { Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287285 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 I tried that as well. It still echos: echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287286 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 Oops I forgot the "". I tried that and now the link disappears but it doesnt post No Directions. Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287287 Share on other sites More sharing options...
AndyB Posted July 1, 2007 Share Posted July 1, 2007 Humour us. Post the actual code that you have presently on the same server as the database you're using. Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287303 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 Woot. I am a moron. I thank all you for your help. It was working but lacking a <td></td> It was hidding elsewhere on the page!! Thanks again, Richard Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287304 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 I have a question. How would I do this samething but without the database having to say NULL? Basically I want it to check if it is blank and than do the if? // Lets see if there is a address to show a map link. $street = $row['street']; { if ($street == "NULL") { echo "<td>". 'No Directions'. "</td>"; } ELSE { echo "<td><a href=directions.php?id=" .$row['id']. ">Map</td>"; } } echo "</tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287308 Share on other sites More sharing options...
GingerRobot Posted July 1, 2007 Share Posted July 1, 2007 I think you're after: if(empty($street)){ } Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287310 Share on other sites More sharing options...
leightr Posted July 1, 2007 Author Share Posted July 1, 2007 Bingo! Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/57927-help-with-simple-if-statement/#findComment-287313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.