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
Share on other sites

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?

Link to comment
Share on other sites

: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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.