Jump to content

Getting mySQL query


owner

Recommended Posts

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

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

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.