MDanz Posted May 11, 2010 Share Posted May 11, 2010 It should echo "test" because there are no results that match the query, instead it echo's "offwal"? <?php mysql_connect("localhost", "Master", "pword"); mysql_select_db("db"); $officialwallpaper = mysql_query("SELECT wallpaper, MAX(points) FROM Contribute WHERE stack LIKE '%test%'")or die (mysql_error()); while($wallrow = mysql_fetch_array( $officialwallpaper)) { $offwall = $wallrow['wallpaper']; } $officialfound = mysql_num_rows($officialwallpaper); if($officialfound==0) { echo "test"; } else { echo "offwall"; } ?> Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/ Share on other sites More sharing options...
Mchl Posted May 11, 2010 Share Posted May 11, 2010 This query will always return one row. Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/#findComment-1056648 Share on other sites More sharing options...
MDanz Posted May 11, 2010 Author Share Posted May 11, 2010 i'm sure the code is correct? how do i change the if statement then.. if no results match the query it should echo "test". Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/#findComment-1056654 Share on other sites More sharing options...
Mchl Posted May 11, 2010 Share Posted May 11, 2010 Perhaps you should first do something with your query. As it is now it doesn't return reliable results. What it's supposed to do? Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/#findComment-1056655 Share on other sites More sharing options...
MDanz Posted May 11, 2010 Author Share Posted May 11, 2010 Perhaps you should first do something with your query. As it is now it doesn't return reliable results. What it's supposed to do? select the wallpaper and the MAX points where the keyword is "test". perhaps i should put the MAX points in the WHERE clause? Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/#findComment-1056658 Share on other sites More sharing options...
Mchl Posted May 11, 2010 Share Posted May 11, 2010 No. You should do it like this. SELECT wallpaper, points FROM Contribute WHERE stack LIKE '%test%' ORDER BY points DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/#findComment-1056660 Share on other sites More sharing options...
MDanz Posted May 11, 2010 Author Share Posted May 11, 2010 thx got it working Link to comment https://forums.phpfreaks.com/topic/201392-mysql-num-rows-not-working/#findComment-1056661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.