Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP NEEDED ON QUERY

Status
Not open for further replies.

anuj576

Programmer
Jul 20, 2008
14
IN
hey guys,
I have made a database using mysql and php. I have also put in a search option. But what i want is that if the item which is being searched for is not in the databse it should return "Database Not Found". I am not able to execute this.
Please help me on this.

$result=mysql_query("SELECT * FROM student_form WHERE roll='$roll_no'") or die(mysql_error());

What i want is that if the roll does not match with any entry in the database it shouls return "Database Not Found".
 
I believe that can be added to the db select.
Code:
mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die("Database Not Found");
Otherwise, you'll need to add an IF statement.

Mark
 
The question and output is kind of misleading, since you want to search in the database it is by default found. Perhaps it be better to say "search term not found [red]in[/red] database"; Which is totally different beast than not finding the database


As for how to do it, well you need to check what results came back if any, and then you know whether it was found and can issue the statement. A simple If statement can do that.

but as was said this is a PHP question, and needs to be posted in the PHP forum here:
forum434



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top