error msg

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ccarrol4
Forum Newbie
Posts: 1
Joined: Fri Jan 09, 2004 3:21 pm

error msg

Post by ccarrol4 »

Hi everyone,
Below is part of my code to display search criteria if found in the database.

Where and how do I write code that just returns a message "No results found" if no search criteria are found in the db>

if (isset($_GET['surname'])) {
echo "<strong>Search Results</strong><hr />";
$db=mysql_connect("localhost","username","password");
mysql_select_db("dbname",$db);

$rs=mysql_query("SELECT * FROM Cathal_Test WHERE INSTR(UCASE(Surname), UCASE('".$_GET['surname']."'))>0",$db);
while ($r=mysql_fetch_array($rs)) {
echo "<a href=\"resultsdemo.php?action=edit&id=".$r[0]."\">".$r[1].", ".$r[2]."</a> (colour: ".strtolower($r['3']).", body part: ".strtolower($r[4]).")<br />";
}
mysql_close($db);
echo "<hr />";
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

Code: Select all

<?php
if (isset($_GET['surname'])) {
echo "<strong>Search Results</strong><hr />";
$db=mysql_connect("localhost","username","password");
mysql_select_db("dbname",$db);

$rs=mysql_query("SELECT * FROM Cathal_Test WHERE INSTR(UCASE(Surname), UCASE('".$_GET['surname']."'))>0",$db);
while ($r=mysql_fetch_array($rs)) {
echo "<a href="resultsdemo.php?action=edit&id=".$r[0]."">".$r[1].", ".$r[2]."</a> (colour: ".strtolower($r['3']).", body part: ".strtolower($r[4]).")<br />";
}
mysql_close($db);
echo "<hr />";
?>
i am not sure but i think you must first check something like:

$r=mysql_fetch_array($rs)
if (!$r)
{
echo "No result";
}
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

If you add:

Code: Select all

if (!$r) { echo "No result."; }
before the line with the mysql_close, it should work.
Post Reply