hi everyone, i have this php code on my search.php file: <?php if ($searchfor == "") {?> You must type a keyword! <?php } else { ?> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM products WHERE status=1 AND (product_id LIKE '".$searchfor."' OR name LIKE '".$searchfor."' OR manufacturer LIKE '".$searchfor."') ORDER BY pricer"); ?> <html table for results> <?php } ?> PHP: when i type the exactly product_id, name or manufacturer the search is ok. but when i type a section of the product_id, name or manufacturer it appears nothing. this thing in asp it's working but not in php. sorry for my english.
product_id LIKE '%$searchfor%' The same for the other search fields. If you don't use the % wild cards, the LIKE will act just as a = (equal).
<?php if ($searchfor == "") {?> You must type a keyword! <?php } else { ?> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM products WHERE status=1 AND (product_id LIKE '%".$searchfor."%' OR name LIKE '%".$searchfor."%' OR manufacturer LIKE '%".$searchfor."%') ORDER BY pricer"); ?> <html table for results> <?php } ?> PHP: I hope it will help.
i have another question: i want the page to display a message like that "no records found" if no records found with this keywords. can anyone give some help?