PDA

View Full Version : سوال: جستجو با فیلتر اطلاعات ورودی



baran.f.a
دوشنبه 06 مهر 1394, 12:08 عصر
سلام
من یک صفحه یجستجو دارم که براساس ورودی کاربر اطلاعات دیتابیس رو فیلتر می کنه و نمایش می ده . این شرط برای or کار می کنه ولی با and نه لطفا راهنماییک کنید خیلی ضروریه .


$statement ="( select pos.serial_code,pos.merchant_id,user.user_name , user.user_family ,merchant.business_name,pos.psp_id,psp.psp_project ,pos_model.pos_ctg,pos_model.pos_model,pos.technic ian_id,psp.psp_name
from pos
INNER JOIN user
on pos.technician_id=user.u_id
INNER JOIN merchant
on merchant.m_id=pos.merchant_id
INNER JOIN psp
on pos.psp_id=psp.id
INNER JOIN pos_model
on pos.model_id=pos_model.id
where pos.last_status=6

) t3
$merchant_id = mysql_real_escape_string($_POST['merchant_id']);
$serial_code = mysql_real_escape_string($_POST['serial_code']);
$terminal = mysql_real_escape_string($_POST['terminal_code']);
$technician = mysql_real_escape_string($_POST['technician']);
$psp = mysql_real_escape_string($_POST['psp_project']);
$project = mysql_real_escape_string($_POST['company_id']);
$type= mysql_real_escape_string($_POST['type']);
$model= mysql_real_escape_string($_POST['pos_model']);


$arr = array();


if ($project!="")
{
$arr[] = " t3.psp_id = '$project' ";
}
if ($merchant_id!="")
{
$arr[] = " t3.merchant_id = '$merchant_id' ";
}
if ($serial_code!="")
{
$arr[] = " t3.serial_code='$serial_code' ";
}
if ($terminal!="")
{
$arr[] = " t3.terminal_code='$terminal' ";
}
if ($technician!="")
{
$arr[] = " t3.technician_id='$technician' ";
}
if ($type !="")
{
$arr[] = " t3.pos_ctg = '$type' ";
}
if ($model!="")
{
$arr[] = " t3.pos_model = '$model' ";
}
$query="SELECT t3.* FROM {$statement}";

if (count($arr) > 0) {

$query .= " WHERE " . implode( "and",$arr );
{