Jump to content

Recommended Posts


Hey all!

 

Right now, I'm working on retrieving records in a database using $_GET.

 

Currently, all of the records that exist in the database, I can retrieve by going to mypage.phtml?id=$id-in-database-that-exists and it returns the information stored.

 

I am trying to use an elseif statement that will return "This record doesn't exist" if the record in the database doesn't exist.

 

Here's a snippet of my code:

 

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

if(!empty($id)) {
        echo "$result

";
} elseif(empty($id) && !isset($id)) {
echo "This page doesn't exist";
}

}

 

Currently, when I visit a page with an id that doesn't exist, nothing shows up. I'd really like it to echo "This page doesn't exist."

 

Help would be appreciated!

 

I've been trying to figure this out for two days, and I can't seem to get it -- no matter how basic it is!

Link to comment
https://forums.phpfreaks.com/topic/131088-solved-non-existent-records-in-database/
Share on other sites

use mysql_num_rows to check if any results have been return from your query

 

if(mysql_num_rows($data) > 0)
{
    while($result = mysql_fetch_array( $data ))
    {
        // display results
    }
}
else
{
    echo 'No results found.';
}

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.