I have want to have a search query that will based on user preference.
$avail = $_POST['avail'];
$sec = $_POST['section'];
$query = "SELECT * ,b.b_Title as title, bac.id as bacid FROM tbl_book AS b
LEFT JOIN tbl_bdetail AS bd ON b.id = bd.b_Title
LEFT JOIN tbl_bacquisition AS bac ON bac.bd_Id = bd.id";
if (count($avail)>0)
{$query.="WHERE bac.ba_Status = '$avail'";}
if (count($sec)>0)
{$query.="WHERE b.section_Id = '$sec'"; }
What I am trying here is that when the user select the $sec option, I want to add the WHERE clause value in my $query, when the user select the $avail option I want to add the WHERE clause values.
My problem is what if the user will select values among the two options? how can I make it happen. any help will do.
/// first check the two values to find which one is returning value??
if($avail != '') {
$cond = "WHERE bac.ba_Status = '$avail' ";
}
elseif ($sec != '')
{
$cond = "WHERE b.section_Id = '$sec'";
}
//if you want to find the result if both options were selected...??? then extend the if { } statement.
//after checking the condition you can use it in mysql_query as,
mysql_query("select * from table_name $cond");
i think this would help you… i`m not so good in explaining…