cliftonbazaar Posted December 14, 2010 Share Posted December 14, 2010 I have the following code $results=mysqli_query($mysqli, $sql_statement); and I wish to find out what happens if no results are returned. I have tried if(!$results) echo "Hello"; but nothing ever gets printed out So how can I find out if $results is empty? James Link to comment https://forums.phpfreaks.com/topic/221570-how-to-find-out-if-nothing-is-returned-from-query/ Share on other sites More sharing options...
trq Posted December 14, 2010 Share Posted December 14, 2010 The general syntax is: if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // free to use $result } else { // no result found } } else { // query failed } Link to comment https://forums.phpfreaks.com/topic/221570-how-to-find-out-if-nothing-is-returned-from-query/#findComment-1146990 Share on other sites More sharing options...
cliftonbazaar Posted December 14, 2010 Author Share Posted December 14, 2010 Thanks for that, works perfectly Link to comment https://forums.phpfreaks.com/topic/221570-how-to-find-out-if-nothing-is-returned-from-query/#findComment-1147012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.