$php_mysql$ Posted August 6, 2011 Share Posted August 6, 2011 tried this but it only shows if there are enrty in table if not it would not print no records $sql = mysql_query("SELECT id, image, title, time FROM tbl WHERE post = 'my_dreams' ORDER BY id DESC LIMIT 0,1"); while($row = mysql_fetch_array($sql)){ if(empty($row)){ echo "no records"; }else{ echo $row['title']. " - ". $row['id']; echo "<br />"; } } Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/ Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Share Posted August 6, 2011 did you try this: if($row=="") Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253261 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 yes tried still it would not print no records Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253263 Share on other sites More sharing options...
radiations3 Posted August 6, 2011 Share Posted August 6, 2011 Try to get some help from the following solved issue : http://www.phpfreaks.com/forums/index.php?topic=340718.0 Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253264 Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 $sql = mysql_query("SELECT id, image, title, time FROM tbl WHERE post = 'my_dreams' ORDER BY id DESC LIMIT 0,1"); while($row = mysql_fetch_array($sql)){ echo $row['title']. " - ". $row['id']; echo "<br />"; } You don't need to check if the '$row' is empty. The results have already been filtered with the query itself. Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253273 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 but i need to print a no records message if there is nothing in the table, how can i achieve that? Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253278 Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 $sql = mysql_query("SELECT id, image, title, time FROM tbl WHERE post = 'my_dreams' ORDER BY id DESC LIMIT 0,1"); if(mysql_num_rows($sql) > 0) { while($row = mysql_fetch_array($sql)){ echo $row['title']. " - ". $row['id']; echo "<br />"; } } else { echo "no records"; } Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253280 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 thanks soo much that helped :-) Link to comment https://forums.phpfreaks.com/topic/244042-check-for-empty-row/#findComment-1253281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.