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 />";
error msg
Moderator: General Moderators
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 />";
?>$r=mysql_fetch_array($rs)
if (!$r)
{
echo "No result";
}
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
If you add:
before the line with the mysql_close, it should work.
Code: Select all
if (!$r) { echo "No result."; }