MDanz Posted December 15, 2009 Share Posted December 15, 2009 $user = mysql_query("SELECT * FROM Users WHERE username LIKE '$letter%' ORDER BY username")or die (mysql_error()); $num_rows = mysql_num_rows($user); if ($num_rows == "0") { echo "<font face='Courier New' font size=5px font color=#FF9900>$letter</font><br /><br />"; echo "<font face='Courier New' font size=3px font color=#FBB917>No Users</font><br>"; } else { echo "<font face='Courier New' font size=5px font color=#FF9900>$letter</font><br /><br />"; echo "<font face='Courier New' font size=3px font color=#FBB917><a href='ustack.php?search=$username&submit=Go!' style='text-decoration: none';>$username</a></font><br>"; } this isn't working now that i've added the if statement..?? Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/ Share on other sites More sharing options...
cags Posted December 15, 2009 Share Posted December 15, 2009 mysql_num_rows returns an integer not a string, therefore it returns 0, not "0". Having said that I'd have thought == evaluates them as the same. But I don't know as I haven't tested it. You will really need to be more specific as to what exactly "if statement not working" means. Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/#findComment-978123 Share on other sites More sharing options...
MDanz Posted December 15, 2009 Author Share Posted December 15, 2009 i get this message Parse error: syntax error, unexpected $end in /home/ustackc1/public_html/stackway.com/users.php on line 101 i tried it without the speech marks and it still not working. line 101 is a blank line. Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/#findComment-978130 Share on other sites More sharing options...
teamatomic Posted December 15, 2009 Share Posted December 15, 2009 "0" == 0 should be true while "0" === 0 should be false as === demans that the types be the same. I would use if ($num_rows > 0) HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/#findComment-978131 Share on other sites More sharing options...
cags Posted December 15, 2009 Share Posted December 15, 2009 It's difficult to say without knowing exactly what lines what. If line 101 is an empty line it's normally the line before or after. Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/#findComment-978133 Share on other sites More sharing options...
teamatomic Posted December 15, 2009 Share Posted December 15, 2009 Why not cut and paste lines 0-101? You probably have mismatched brackets or quotes. Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/#findComment-978143 Share on other sites More sharing options...
MDanz Posted December 15, 2009 Author Share Posted December 15, 2009 missed closing bracket on while loop.. thx for help Link to comment https://forums.phpfreaks.com/topic/185291-if-statement-not-working/#findComment-978145 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.