Jump to content

Recommended Posts

You could look into mysql_num_rows() to see if any data exists in the database.

 

$sql1 = "SELECT * FROM `table`";
$res1 = mysql_query($sql1) or die(mysql_error());
$num_rows = mysql_num_rows($res1);

if($num_rows == '') { //if number of rows is equal to nothing
echo "There is no data in the database.\n";
}else {
//echo your table data here
}

 

Is that what you wanted?

  • 2 weeks later...

this code only gives me total number of rows in the database table

But

i want to search database values and the output should be like

 

if(rows found) then

 

print search results are:

 

print the search result data table;

 

else >:(

 

print "sorry no results found";

 

please help me.

Elaborate a little more please

 

sorry if i got any errors below or I didnt understand your question, im a little rusty, been off and on php for months.

 

<?php
$title = "Moby Dick";
$sql = mysql_query("SELECT `title`,`author`,`book` FROM `library` WHERE `title` LIKE '$title%'");

if(mysql_num_rows($sql) > 0){

$book = mysql_fetch_array($sql);
echo $book['title'];

}else{

echo "Sorry, but there was no books found with the name ".$title;

}
?>

imho phpsensei and lostprophetpunk answer same like i want to say

but plz.. we don't understand what do you want!? please describe

 

1. what table do you want to search?

 

2. is this ALL table on 1 database or just 1 table?

 

3. in 1st u said Data exist (mean data inside table) but next you said rows (rows name maybe?).. where the correct?

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.