Jump to content

[SOLVED] non-existent records in database


careym1989

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.';
}

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.