nathanmaxsonadil Posted August 15, 2007 Share Posted August 15, 2007 I'm trying to get it to display something if there's nothing in the database the current code I have now is if($query <= 0) { echo "<div id='posts'><h2>Nothing to display</h2> <p>Sorry we don't have anything to display.<br/>Suscribe to our <a href='http://myurl.com/feednews'>rss</a> feed for updates!</p></div>"; } else { //my code to execute if more that 0 in database } however that does not display anything even when there is 0 in the database what should I use instead? Link to comment https://forums.phpfreaks.com/topic/64960-ifquery/ Share on other sites More sharing options...
willpower Posted August 15, 2007 Share Posted August 15, 2007 what is $query if it is a result then it will include something presumably you should be looking for the number if results returned...and i would find $query a strange var to use....can you expand. Will Link to comment https://forums.phpfreaks.com/topic/64960-ifquery/#findComment-324152 Share on other sites More sharing options...
nathanmaxsonadil Posted August 15, 2007 Author Share Posted August 15, 2007 $query is a mysql query $query = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 10") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/64960-ifquery/#findComment-324153 Share on other sites More sharing options...
jcombs_31 Posted August 15, 2007 Share Posted August 15, 2007 you can check if any rows were returned if mysql_num_rows($query) == 0 { do something } Link to comment https://forums.phpfreaks.com/topic/64960-ifquery/#findComment-324159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.