Trying to add some more functionality to a search page I'm doing. It's for a catalog system that I'm making searchable and it works, but I added it a checkbox to the form that says "match words exactly" or something like that and that's what I'm trying to do but it doesn't seem to work.
PHP Code:
if ($_POST['search']) {
if (strlen($_POST['keywords'])>2) {
$error=0;
if ($_POST['exact']=="on") $keyword = $_POST['keywords'];
else $keyword = "%" . $_POST['keywords'] . "%";
$sqlquery = "SELECT id, category, platform, name, manufacturer, description, price FROM catalog WHERE ";
if ($_POST['searchOptions']==1) $sqlquery.="name LIKE '$keyword'";
elseif ($_POST['searchOptions']==2) $sqlquery.="description LIKE '$keyword'";
elseif ($_POST['searchOptions']==3) $sqlquery.="manufacturer LIKE '$keyword'";
else $sqlquery.="name LIKE '$keyword' OR description LIKE '$keyword' OR manufacturer LIKE '$keyword'";
$sqlquery.=" AND delflag=0";
echo $sqlquery;
$result = dbconnect($sqlquery);
$number = mysql_numrows($result);
/////////////////////////////////////////////////////////
I suppose I could totally change the query if $exact is on and change LIKE to =, but that would involve extra coding which I may eventually do, but I would like to know if there is an easier way. Thanks.
Bookmarks