I need some help guys basically I want the form to search all products if no $searchwords are posted. But I can't figure out how to add the "Where" clause and the "OR" clause to this coding for it to work properly. If anyone can help I would appreciate it. Here is what I have right now.
But now by default of no searchwords are submitted there are 3 checkboxes checked default and whats being submitted is this:
SELECT * FROM products OR descr LIKE '%%' OR fulldescr LIKE '%%' OR meta_keywords LIKE '%%'
But as stated how do you setup the php to order the "WHERE" and "OR" clauses based on the information submitted?
if (isset($_POST['submit'])){
if (!$searchwords){
$searchall = "SELECT * FROM products";
} else {
$searchall = "SELECT * FROM products WHERE product LIKE '%$searchwords%'";
}
echo $searchall."<br />";
$byshortdescr = $_POST['posted_data']['shortdescr'];
$byfulldescr = $_POST['posted_data']['fulldescr'];
$bykeywords = $_POST['posted_data']['keywords'];
if ($byshortdescr){
$searchall.= " OR descr LIKE '%$searchwords%'";
}
if ($byfulldescr){
$searchall.= " OR fulldescr LIKE '%$searchwords%'";
}
if ($bykeywords){
$searchall.= " OR meta_keywords LIKE '%$searchwords%'";
}
echo $searchall."<br />";
}
And my html form with php
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table cellspacing="1" width="100%">
<tr>
<td height="10" width="20%"><b>Search For:</b></td>
<td height="10" width="80%">
<input type="hidden" name="mode" value="search" />
<input type="text" style="width:70%" name="searchwords" size="30" value="" />
<input type="submit" name="submit" value="Search" />
</td>
</tr>
<tr>
<td height="10" width="20%"><b>Search In:</b></td>
<td height="10" width="80%">
<table cellspacing="0" cellpadding="0">
<tr>
<td width="5"><input id="posted_data_by_shortdescr" type="checkbox" checked="checked" name="posted_data[shortdescr]" /></td>
<td nowrap="nowrap"><label for="posted_data_by_shortdescr">Short Description</label></td>
<td width="5"><input id="posted_data_by_fulldescr" type="checkbox" checked="checked" name="posted_data[fulldescr]" /></td>
<td nowrap="nowrap"><label for="posted_data_by_fulldescr">Detailed Description</label></td>
<td width="5"><input id="posted_data_by_keywords" type="checkbox" checked="checked" name="posted_data[keywords]" /></td>
<td nowrap="nowrap"><label for="posted_data_by_keywords">Search Keywords</label></td>
</tr>
</table>
</td>
</tr>
</table>
</form>