careym1989 Posted November 2, 2008 Share Posted November 2, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/131088-solved-non-existent-records-in-database/ Share on other sites More sharing options...
wildteen88 Posted November 2, 2008 Share Posted November 2, 2008 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.'; } Quote Link to comment https://forums.phpfreaks.com/topic/131088-solved-non-existent-records-in-database/#findComment-680590 Share on other sites More sharing options...
careym1989 Posted November 2, 2008 Author Share Posted November 2, 2008 Works perfectly. Marked this as "Solved!" Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/131088-solved-non-existent-records-in-database/#findComment-680592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.