Can someone please double check my search query to make sure it is the minimum and most efficient coding. My goal is an exact match search of field1 from my database table and list field1, field2, field3, field4 and field5 if the part number is in the database or no results if it is not. The query works as is but I have a feeling it could be done more efficiently or professionally and minimum work for my poor little server. Thanks in advance.
<?php
//connect to the database
include("./databaseconnect.php");
//get query
$q=$_GET['q'];
//convert query to uppercase & remove all spaces and special charactars
$q=strtoupper(preg_replace("/[^A-Za-z0-9]/","",$q));
//if blank query
if ($q == "")
{
echo "You did not enter a search term";
} else {
//exact match only query
$query = "SELECT * FROM ".$dbtable." WHERE field1 like \"$q\"";
$result = mysql_query($query);
//if query returns no results
if(mysql_num_rows($result)==0)
{
echo "<span class=\"noresults\">There were no results for your search</span>";
//display database results
} else {
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<span class=\'results\'>SEARCH RESULTS</span><br />
<span class=\'list\'>Part Number: ".$row['field1']."<br />
Manufacturer: ".$row['field2']."<br />
Cost per unit: ".$row['field3']."<br />
Warehouse Location: ".$row['field4']."<br />
Quantity Available: ".$row['field5']."<br />
Notes: ".$row['field6']."<br />
</span>";
}
}
}
?>