我对PHP和SQL很陌生;我正在编写一个SQL查询,用以下逻辑显示记录:
日期:_________(日期选择器)-日期选择器(Till:______________) 销售代理:下拉( dehi,孟买,.) 手机:__________ (文本)
所需成果组合:
所有三个组合真-(用户填写日期,销售代理,移动)。
任何一个组合都是真实的。(用户只填充一个参数中的任何一个。)
只有两个组合是真实的。(用户填写两个参数组合,即日期和移动(或)移动和销售代理(或)销售代理和日期)
Problem:我不能只做一个组合。
下面是我的SQL查询和页面语法:
if(isset($_POST["submit"]))
{
$date11=$_POST["date1"];
$date22=$_POST["date2"];
$salesagent1=$_POST["salesagent"];
$mobile1=$_POST["mobile"];
$result = "select
ordertable.order_date,
ordertable.order_id,
customer.cust_name,
customer.cust_mobile,
customer.cust_email,
customer.cust_city,
ordertable.quantity,
ordertable.total,
orderstatus.order_sta,
salesagent.name
from customer inner join ordertable
on customer.custid=ordertable.cust_id inner join salesagent
on salesagent.said=ordertable.sales_id inner join orderstatus
on orderstatus.id= (select order_statusid from orderhistory where order_id1= ordertable.order_id order by date_added desc limit 1)
where (ordertable.order_date between '$date11' and '$date22') or (customer.cust_mobile='$mobile1') or (ordertable.sales_id='$salesagent1')
order by ordertable.order_id desc";
$records=mysqli_query($CON,$result);发布于 2016-11-07 08:36:53
在每个参数为空时,将null或您选择的任何操作设置为:
$result = "select
ordertable.order_date,
ordertable.order_id,
customer.cust_name,
customer.cust_mobile,
customer.cust_email,
customer.cust_city,
ordertable.quantity,
ordertable.total,
orderstatus.order_sta,
salesagent.name
from customer inner join ordertable
on customer.custid=ordertable.cust_id inner join salesagent
on salesagent.said=ordertable.sales_id inner join orderstatus
on orderstatus.id= (select order_statusid from orderhistory where order_id1= ordertable.order_id order by date_added desc limit 1)
where ('$date11' IS NULL OR '$date22' IS NULL OR ordertable.order_date between '$date11' and '$date22') AND ('$mobile1' IS NULL OR customer.cust_mobile='$mobile1') AND ('$salesagent1' IS NULL OR ordertable.sales_id='$salesagent1')
order by ordertable.order_id desc";https://stackoverflow.com/questions/40460416
复制相似问题