Page 1 of 1

error msg

Posted: Fri Jan 09, 2004 3:21 pm
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 />";

Posted: Fri Jan 09, 2004 3:25 pm
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";
}

Posted: Fri Jan 09, 2004 5:01 pm
by Bennettman
If you add:

Code: Select all

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