Hi
Iam new with php & making searching module for client.for searching i select two values from DROP DOWN list i.e: Category & City, Third value is the search string entered by the user like Hussain & co.
Now wht i want is that , it giv me results by searching in whole DB depending up category & City. In simple words first ir search for "Hussain", then "&" then "co".
It'll be good if it cater special characters.
Looking forward for ur kind response.
//////////index.php/////////////
<form name="s_frm" method="post" action="search.php">
<input type="text" name="search_txt" maxlength="20">
<select name="kat">
<option value="">--Select--</option>
<option value="Firm" >Firm</option>
<option value="Product">Product
</option>
<option value="Project">Project
</option>
<option value="Service">Service
</option>
</select>
<select name="sity">
<option value="">---City---</option>
<option value="Islamabad">Islamabad
</option>
<option value="Rawalpindi">Rawalpindi
</option>
</select>
<input type="submit" name="search" value="Search">
</form>
/////////////////////////////////////////////////////////////
//////////search.php///////////////////////////////////
<?php
//make connection with DB
include ("connect2db.php");
$search_txt=$_REQUEST["search_txt"];
$kat=$_REQUEST["kat"];
$sity=$_REQUEST["sity"];
//trim whitespace from the stored variable i.e from left & right.
$trimmed = trim($search_txt);
switch($kat)
{
case 'Firm':
{
if($sity=="")
{
$query=mysql_query("select distinct(firm.fi_name), firm.fi_reg_name, firm.fi_views,firm_info.f_description
FROM firm,firm_info
where firm.fi_name like '%$trimmed%'
AND firm_info.fi_name like '%$trimmed%'
"); //OR firm.fi_reg_name like '%$trimmed%'
break;
}
else
{
$query=mysql_query("select distinct(firm.fi_name), firm.fi_reg_name, firm.fi_views,firm_info.f_description
FROM firm,firm_info
where firm.fi_name like '%$trimmed%'
AND firm_info.fi_name like '%$trimmed%'
AND firm_info.f_city like '%$sity%'
");
break;
}
}
case 'Product':
{
if($sity=="")
{
$query=mysql_query("select pd_description,fi_name,pd_name,pd_view
from product_detail
where (pd_description like '%$trimmed%'
or pd_name like '%$trimmed%')
");
break;
}
else
{
$query=mysql_query("select pd_description,fi_name,pd_name,pd_view
from product_detail
where (pd_description like '%$trimmed%' or pd_name like '%$trimmed%')
AND pd_city='$sity'
");
break;
}
}
case 'Project':
{
if($sity=="")
{
$query=mysql_query("select pro_description,fi_name,pro_name,pro_views
FROM projects
where (pro_description like '%$trimmed%' or pro_name like '%$trimmed%')
");
break;
}
else
{
$query=mysql_query("select pro_description,fi_name,pro_name,pro_views
FROM projects
where (pro_description like '%$trimmed%' or pro_name like '%$trimmed%')
AND pro_city='$sity'
");
break;
}
}
case 'Service':
{
if($sity=="")
{
$query=mysql_query("select svc_description,fi_name,svc_title,svc_views
FROM services
where (svc_description like '%$trimmed%' or svc_title like '%$trimmed%')
");
break;
}
else
{
$query=mysql_query("select svc_description,fi_name,svc_title,svc_views
FROM services
where (svc_description like '%$trimmed%' or svc_title like '%$trimmed%')
AND svc_city='$sity'
");
break;
}
}
}
while($data=mysql_fetch_array($query))
{
if($kat=="Firm")
{
$fi_name = $data["fi_name"];
$fi_reg_name = $data["fi_reg_name"];
$description = $data["f_description"];
}
if($kat=="Product")
{
$fi_name = $data["fi_name"];
$name = $data["pd_name"];
$description = $data["pd_description"];
}
if($kat=="Project")
{
$fi_name = $data["fi_name"];
$name = $data["pro_name"];
$description = $data["pro_description"];
}
if($kat=="Service")
{
$fi_name = $data["fi_name"];
$name = $data["svc_title"];
$description = $data["svc_description"];
}
echo $fi_name. "  ( " . $name . " )";
?>
///////////////////////////////////////////////////////