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? Link to comment https://forums.phpfreaks.com/topic/77770-getting-mysql-query/ 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! ?> Link to comment https://forums.phpfreaks.com/topic/77770-getting-mysql-query/#findComment-393669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.