如何商品信息多个sql查询搜索
1、商品信息小搜索
2、首先要了解明白SQl语句
像
select * from goods
select * from goods where id=23
select * from goods where id=23 and price>50
之类的
3、商品搜索类型选择
window['f'] = $("#form").ligerForm({
inputWidth: 170,labelWidth: 90,space: 40,
fields:[
{display:"下单时间从",name:"FirstTime",newline:true,type:"date"},
{display:"到",name:"LastTime",newline:true,newline:false, type:"date"},
{display:"订单状态",name:"Status"},
{display:"商铺号:",name:"ShopId",newline:false},
],
buttons:[
{text:'搜索',width:50,click:select},
{text:'导出',width:50,click:importType}
]
});
4、点击搜索以后
5、搜索代码
6、控制层代码(自己写的哦,不是网上复制的了)
/**
*
* 模糊查询订单信息
*/
public function GetOrder()
{
//获取json
$jsonstr=$_POST['json'];
$query=json_decode($jsonstr,true);//字符处理
$first=$query['FirstTime'];//获取开始时间
$last=$query['LastTime'];//获取介绍时间
$status=$query['Status'];//商品状态
$shopid=$query['ShopId'];//商品id号
//************************************************************
//重要代码在下一个方法里面,运行的时候把下一个方法的代码复制在这里,主要是重点介绍了
//************************************************************
//加载model,获取数据
$this->load->model('TestsDao');
$users_qry = $this->TestsDao->getOrder($sql);
//传数据到前台
echo json_encode($users_qry);
}
7、重点sql语句的处理
$sql= "select * from ht_order o,tb_user u where o.BuyerId=u.UserID ";//sql语句,这是基本的sql查询语句,意思是从查到订单
if($first!=null && $last!=null && $first!='' && $last!='')//判断了,如果从前天传来的时间是空的,那么久对sql语句进行字符处理,
{
$first=substr($first,0,10);//截取时间的前10位
$first=$first.(' 00:00:00');//开始时间字符处理
$last=substr($last,0,10);//截取时间的前10位
$last=$last.(' 23:59:59');//介绍时间字符处理
$sql = $sql.(" and SubmitTime between '$first' and '$last' ");//sql语句字符处理
}
if($status!=null && $status !='')//判断用户是否输入了状态,如果输入了状态,那么对sql语句进行处理
{
$sql = $sql.(" and status=$status ");
}
if($shopid!=null && $shopid!='')//判断用户是否输入了商品的id号
{
$sql= $sql.(" and shopid=$shopid ");
}
8、测试结果