zoukankan      html  css  js  c++  java
  • 代码实现模糊搜索,以及排序

    //分页条件展示结果
    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);

  • 相关阅读:
    PHP header函数使用教程
    mysql show processlist 命令检查mysql lock
    MySQL
    background-position 用法详细介绍
    Windows下Mysql主从配置(Mysql5.5)
    Tcl介绍和基础语法
    研发项目管理
    VCS 查看代码覆盖率
    Openrisc的or1200
    MY $MYVIMRC
  • 原文地址:https://www.cnblogs.com/lsl321/p/7994276.html
Copyright © 2011-2022 走看看