nyoung2005
Programmer
Hi,
I am trying to get PHP to search my mySQL database. Everything is fine at the moment except for the query is not searching for singular items. For example if you type in mint it comes up with everything with mint in it but if mints is typed in it does not bring up everything with mint!
I have a feeling that this is more of a mySQL issue even though it is coded in PHP.
Can anyone tell me where I am going wrong in my query?
Many Thanks
I am trying to get PHP to search my mySQL database. Everything is fine at the moment except for the query is not searching for singular items. For example if you type in mint it comes up with everything with mint in it but if mints is typed in it does not bring up everything with mint!
I have a feeling that this is more of a mySQL issue even though it is coded in PHP.
Can anyone tell me where I am going wrong in my query?
Many Thanks
PHP:
$searchString = $_POST['searchString'];
include("dbProductsConnect.php");
$sql = "SELECT * FROM productlist WHERE title LIKE '%$searchString%'";
$rs=mysql_query($sql,$conn) or die("Could not execute query");
$noOfRecords = 0;
$list = "<br/>";
$list .= "<hr>";
while($row= mysql_fetch_array($rs) )
{
$productID = $row["productID"];
$postedTitle = $row["title"];
$postedDescription = $row["description"];
$postedPrintArea = $row["printarea"];
$postedLeadTime = $row["leadtime"];
$postedFastTrack = $row["fasttrack"];
$postedCategory = $row["category"];
$postedMinQuantity = $row["minquantity"];
$imageDisplay = $row["image2"];
$noOfRecords++;
$list .= "<span class=\"productCatalogueItems\"><b>Item " . $noOfRecords . ": </b></span>";
$list .= "<span class=\"pageMenuLinks\"><span class=\"productCatalogueItems\"><a href='product.php?cmd=product&productID=$productID&category=$postedCategory&title=$postedTitle&description=$postedDescription&image2=$imageDisplay&printarea=$postedPrintArea&minquantity=$postedMinQuantity&fasttrack=$postedFastTrack&leadtime=$postedLeadTime'>".$row["title"]."</span></a></span><br/><br/>";
$list .= "<p class=\"productCatalogueItems\">$postedDescription</p>";
$list .= "<hr>";
}
if ($noOfRecords==0)
{
echo "<p>Your search returned 0 products</p>";
echo("<p><a href='javascript:history.back(1);'>Back</a></p>");
}
else if ($searchString == "")
{
echo "<p>You did not type anything in the search box</p>";
echo("<p><a href='javascript:history.back(1);'>Back</a></p>");
}
else
{
echo("<span class=\"productCatalogueItems\">Below are your results for <b>$searchString</b>:</span><br/>");
echo($list);
}