Jump to content

check for empty row?


$php_mysql$

Recommended Posts

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

$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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.