Need help with "If" statement for MySQL search
Posted: Mon May 16, 2005 9:26 am
Hi,
I have a search box which takes a form and looks through the database for possible matches. I need an If statement to return an echo that the record was not found. I have attempted it at the bottom, but I get an error.
Here is the code for the search.php script;
I have a search box which takes a form and looks through the database for possible matches. I need an If statement to return an echo that the record was not found. I have attempted it at the bottom, but I get an error.
Here is the code for the search.php script;
Code: Select all
<?
mysql_connect("localhost","","");
mysql_select_db("audit");
$search=$_POST["search"];
$result = mysql_query("SELECT * FROM dedicated WHERE customer LIKE '%$search%'");
//grab all the content
while($r=mysql_fetch_array($result))
{
$asset=$r["asset"];
$customer=$r["customer"];
//display the row
if ($r=mysql_fetch_array ="") {
echo "No records found";
}
else {
echo "<tr><td><a href='viewall.php?varl=".$asset."'>".$asset."</a></td><td>".$customer."</td></tr> ";
}
?>