Jump to content

[SOLVED] Num Rows? Results = 0?


eRott

Recommended Posts

I have a section of code which grabs the content from the database:

 

$sql = "SELECT * FROM beepbopboop WHERE entry_id = '$entryid' ORDER BY id DESC";
$result = mysql_query($sql, $conn) or die(mysql_error());

while ($list = mysql_fetch_array($result)) {
	echo "blah blah blah {$list['how_to_build_an_icbm']} blah blah blah";
}

 

How would I check to see if any content (rows) have been returned, and if there are none, display something else?

 

Thanks,

Regards.

Link to comment
https://forums.phpfreaks.com/topic/81068-solved-num-rows-results-0/
Share on other sites

<?php

$sql = "SELECT * FROM beepbopboop WHERE entry_id = '$entryid' ORDER BY id DESC";
$result = mysql_query($sql, $conn) or die(mysql_error());

if (mysql_num_rows($result) < 1){
   //no results returned
} else {
   //results found
}

?>

That's basically what I tried (slightly different code), however, it needs to be in a while statement. With this code, nothing happens. No error's. Just, nothing.

 

$sql = "SELECT * FROM blahblah WHERE entry_id = '$entryid' ORDER BY id DESC";
$result = mysql_query($sql, $conn) or die(mysql_error());

$chknum = mysql_num_rows($result);

while ($list = mysql_fetch_array($result)) {
	if ($chknum < 1) {
	echo "blah blah NO RESULTS";
	} else {
	echo "blah blah RESULTS FOUND";
	}
}

 

Any ideas?

:P I noticed and fixed it within the time it took you to post that reply. Anyway:

 

$sql = "SELECT * FROM APPLE_ORANGE WHERE entry_id = '$entryid' ORDER BY id DESC";
$result = mysql_query($sql, $conn) or die(mysql_error());

$chknum = mysql_num_rows($result);

if ($chknum < 1) {

	// NO RESULTS

} else {

	while ($list = mysql_fetch_array($result)) {

		// RESULTS

	}

}

 

Thanks for your help pocobueno1388.

 

Take care.

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.