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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.