代码实现模糊搜索,以及排序

//分页条件展示结果
function getByPagePro($table,$page,$where=null,$orderBy=null,$pageSize=2){
global $totalRows;
$totalRows=getAllRows($table,$where);
global $totalPage;
$totalPage=ceil($totalRows/$pageSize);
if($page<1||$page==null||!is_numeric($page))$page=1;
if($page>=$totalPage)$page=$totalPage;
$offset=($page-1)*$pageSize;
$sql="select p.id,p.pName,p.pSn,p.pNum,p.mPrice,p.iPrice,p.pDesc,p.pubTime,p.isShow,p.isHot,c.name from shop_pro as p join shop_cate c on p.cId=c.id {$where} {$orderBy} limit {$offset},{$pageSize}";
$rows= fetchAll($sql);
return $rows;
}

//JavaScript实现实现搜索
function search(){
if(event.keyCode==13){
var val=document.getElementById("search").value;
window.location="listPro.php?keywords="+val;
}
}
function change(val){
window.location="listPro.php?order="+val;
}

@$page=$_REQUEST['page']!=null?$_REQUEST['page']:1;
@$keywords=$_REQUEST['keywords']?$_REQUEST['keywords']:null;
@$order=$_REQUEST['order']?$_REQUEST['order']:null;
$orderBy=$order?"order by $order":null;
$where=$keywords?"where pName like '%{$keywords}%'":null;
$pageSize=2;
$rows=getByPagePro("shop_pro",$page,$where,$orderBy);

posted @ 2017-12-06 18:49  lsl321  阅读(500)  评论(0编辑  收藏  举报