owner Posted November 17, 2007 Share Posted November 17, 2007 Hello, I took some info out of my database. I want to display an error page if their are no rows in the database. How would I go about doing that. I have this: $query = I execute my query here. Taken it out so you don't connect to my database Muahahahhaah $row = mysql_fetch_row($query) if ($row == '') { echo 'Their is nothing in the database!'; }else{ echo 'Yes, the database does home info in it.'; } What would I put to make this work? Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 17, 2007 Share Posted November 17, 2007 That is not how you do that type of syntax try: <?php $condition = ''; $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $query = "select count(*) from tablename ".$condition; $result=mysql_query($query); if(!$result){echo "SQL Error - ".mysql_error()."<br>".$query;return;} $Nbrtable=mysql_result($result,0); if ($Nbrtable = 0){ echo 'Database is empty'; } else { echo 'Database has at least one record!'; } // Hope this helps! ?> Quote Link to comment 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.