数据操作类:

<?phpclass DBHelper{public $conn;/*** 得到数据库连接 成功返回true,失败返回false* Enter description here ...* @param unknown_type $user* @param unknown_type $pwd* @param unknown_type $dbname* @param unknown_type $host*/function getConn($user,$pwd,$dbname,$host = "localhost"){$this->conn = mysql_connect($host,$user,$pwd);if (!$this->conn){return false;}mysql_select_db($dbname,$this->conn);   return true;            }/*** 返回查询的result* @param unknown_type $table 待查询的表* @param unknown_type $cols 待查询的列的数组 如array("col1","col2");* 如果想给列 重命名 则使用 array("newcol1"=>"col1","newcol2"=>"col2") ; * null 表示查询所有* @param unknown_type $conditions where后的条件数组按如此格式来 array("col"=>array("> xx"=>"AND","< yy"=>"")) 表示 col 列 大于 xx * 并且小于yy的结果 。array("col"=>array("LIKE 'xx%'"=>"")) 模糊搜索* 注意xx,yy 为字符串时要用''扩住,中间的条件才能用AND 或者OR,末尾条件用""表示* null 表示无条件* @param unknown_type $order 排序数组 如 array("col1"=>"asc","col2"=>"desc"); null 表示默认排序* @param unknown_type $limit 数据条目,如 array(1=>10) 表示limit 1,10;  null 表示默认*/function getRow($table,$cols,$conditions,$order,$limit){$sql = "SELECT ";$tmp = "";if($cols != null){while((list($k,$v) = each($cols)) !== false){$tmp =$tmp.$v.",";if(!is_numeric($k)){$tmp = substr($tmp, 0,strlen($tmp)-1)." as {$k},";}}$tmp = substr($tmp, 0,strlen($tmp)-1)." FROM {$table}";}else {$tmp = "* FROM {$table}";}$sql = $sql.$tmp;if($conditions != null){$tmp = " WHERE ";while((list($k,$v) = each($conditions)) !== false){if((list($k1,$v1) = each($v)) !== false){$tmp = $tmp."{$k} {$k1} {$v1}"; }}$tmp = rtrim($tmp);$sql = $sql.$tmp;}if($order != null){$tmp = " ORDER BY ";while((list($k,$v) = each($order)) !== false){$tmp = $tmp."{$k} {$v},"; }$tmp = substr($tmp, 0,strlen($tmp)-1);$sql = $sql.$tmp;}if($limit != null){$tmp = " limit ";if((list($k,$v) = each($limit)) !== false){$tmp = $tmp."{$k},{$v}";}$sql = $sql.$tmp;}//echo $sql;$result = mysql_query($sql);return $result;}function closeDb(){if($this->conn != null)mysql_close($this->conn);}/*** * 返回mysql标准时间字符串* 注意这个date的获得和php的配置有关系,而php默认返回的UTC* 如果不符合你的标准,需要在php.ini中将配置做相应的更改*/function getDateStr(){return date("Y-m-d H:i:s");}}?>

response封装:

<?phpinclude 'dbhelper.php';class Response{public $total = 0;public $records = 0;public $page; // get the requested pagepublic $rows =array();private  $limit; // get how many rows we want to have into the gridprivate  $sidx; // get index row - i.e. user click to sortprivate  $sord; // get the directionfunction Response($page,$rows,$sidx,$sord){$this->page = $page;$this->limit = $rows;$this->sidx = $sidx;$this->sord = $sord;if(!$this->sidx)$this->sidx = 1;}/*** 通过指定条件查询将结果填入response中* @param unknown_type $table 表名* @param unknown_type $cols 待查询的列的数组 如array("col1","col2");* 如果想给列 重命名 则使用 array("newcol1"=>"col1","newcol2"=>"col2") 为null 表示查询所有* @param unknown_type $conditions where后的条件数组按如此格式来 array("col"=>array("> xx"=>"AND","< yy"=>"")) 表示 col 列 大于 xx * 并且小于yy的结果。array("col"=>array("LIKE 'xx%'"=>"")) 模糊搜索* 注意xx,yy 为字符串时要用''扩住,中间的条件才能用AND 或者OR,末尾条件用""表示* null 表示无条件*     ;null 表示无条件*/public function fillResponse($table,$cols,$conditions){$helper = new DBHelper();if($helper->getConn("root", "root", "dbcd")){$result = $helper->getRow($table, null, $conditions,null,null);if($result){$count = mysql_num_rows($result);$this->records = $count;if($count > 0){$this->total = ceil($count/$this->limit);}else{$this->total = 0;}if($this->page > $this->total)$this->page = $this->total;$start = $this->limit*$this->page - $this->limit;if($start < 0) $start = 0;$result = $helper->getRow($table, $cols, $conditions, array($this->sidx=>$this->sord), array($start=>$this->limit));$i = 0;while(($row=mysql_fetch_array($result,MYSQL_ASSOC))!=false){$this->rows[$i] = $row;$i++;}}else{// 查询失败}$helper->closeDb();}else {// 未成功连接数据库}} }?>

使用:

include 'php/response.php';$conditon = null;$response = new Response($_GET['page'], $_GET['rows'], $_GET['sidx'], $_GET['sord']);if(filter_has_var(INPUT_GET, "searchField")){$conditon = array($_GET['searchField']=>array("LIKE '{$_GET['searchString']}%'"=>""));}$response->fillResponse("factory",null, $conditon);print_r(json_encode($response));

As mentioned above posting search data differs from custom and toolbar searching. When the find button is clicked, jqGrid adds three parameters to the url (again with _search=true), in name=value pairs:

  • sField: the 'searchField', the value comes from the index in colModel
  • sValue: the 'searchString', the value is the entered value
  • sOper: the 'searchOper', the value is the type of search - see sopt array

For example if the field index is invid, operation is equal, and the searched value is 123, then the string that is posted to the server look like:

http://localhost/demo35/server.php?...&searchField=invid&searchString=123&searchOper=eq

详见:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:singe_searching

PHP jqGrid 表格数据更新帮助代码相关推荐

  1. jqgrid表格下拉搜索多选框优化—使用select下拉多选插件

    jqgrid表格插件应该是表格插件中最强大吧,最近项目需要使用jqgrid但又要根据项目需求进行一些私人订制,还好jqgrid的源码写清晰易懂. jqgrid有个下拉搜索的功能,我们先看下官网的展示, ...

  2. jqGrid 表格底部汇总、合计行footerrow处理

    jqGrid提供了表格底部汇总.合计行功能,我们先看下user-guide关于jqGrid合计行都有哪些说明?然后再看个DEMO,看看jqGrid表格底部汇总.合计行到底如何实现. 1.user-gu ...

  3. jqGrid表格 样式设置

    页面的<style>标签里添加下列代码, 可设置jqGrid表格的字体样式大小 .ui-jqgrid .ui-jqgrid-title{font-size:22px;} /*修改grid标 ...

  4. ag-grid 表格数据更新

    有时候我们会涉及到数据更新,但是又不想刷新整个页面,那么就可以单独对表格中的数据进行更新.以下有三种更新情况:表格整个数据的更新:更新一行数据:更新单元格数据. 最初的表格数据如下图: 一 更新整个表 ...

  5. jqGrid表格实例

    1.导入所需要用的js.css文件 一般jqgrid表格用这些就够了,如果你希望好看一点可以在网上下载主题包然后导入进去 <!--jqgrid引用--><link rel=" ...

  6. JqGrid 表格水平滚动条不显示导致表格字段没显示全无法查看问题处理(解决)

    最近使用了JqGrid表格,但是在设置水平滚动条时,一直没有效果,列也没有显示全.效果如下所示: 解决这个问题的方法: 如代码块中所示,必须要像下面一样设置下面的三个属性,shrinkToFit一定是 ...

  7. 关于jqGrid 表格部分空白 的问题;

    jqGrid  表格部分空白 大部分原因是表格的宽度出现问题:主要原因如下: 1:在启用 colModel中的width在没有使用默认值而是重新赋值的情况下,width赋值出现问题,一般此情况只需要在 ...

  8. mysql表格的代码_mySQL表格内容用代码添加

    通过代码对表格内容操作: 1.添加数据 insert into Info values('p009','张三',1,'n001','2016-8-30 12:9:8') ; 给特定的列添加数据 ins ...

  9. python简单代码编写-python读写Excel表格的实例代码(简单实用)

    安装两个库:pip install xlrd.pip install xlwt 1.python读excel――xlrd 2.python写excel――xlwt 1.读excel数据,包括日期等数据 ...

最新文章

  1. 阅读10、11、12章
  2. 关于webStrom-11.1配置less且自动生成.css和自动压缩为.min.css/.min.js
  3. npm命令的--save 与--save-dev
  4. 如何阵列平面_Proe/Creo如何使用点阵列——通过内部草绘创建
  5. jvm性能调优实战 -54Jetty NIO机制导致堆外内存溢出Direct buffer memory OOM
  6. 面对需求总是被Boss怒改,产品经理该怎么办?
  7. Sklearn参数详解—贝叶斯
  8. 配置mysql读写主从_Mysql主从配置,实现读写分离
  9. Leetcode-169 Majority Element
  10. 软考新思维--2017年上半年信息系统项目管理师上午试题分析与答案(试题6-10题)...
  11. 面向对象进阶(二)----------类的内置方法
  12. catia如何整列加工_CATIA V5 R20加工模块的自动编程方法
  13. bldc 原理 方波控制_【百问百答】ST 电机控制实战问答合辑 | 连载之一
  14. usb一转多 树莓派zero_树莓派 Zero USB/以太网方式连接配置教程
  15. linux c 编程手册,Linux C/C++编程手册查阅方法
  16. Redis连接的客户端(connected_clients)数过高或者不减的问题解决方案
  17. css颜色 333是什么颜色,纯css实现的颜色扇附图
  18. FeedDemon 实务讲义
  19. 孔雀东南飞用mysql存储_社区考试公共基础知识:乐府双璧
  20. mysql表空间查询

热门文章

  1. 看着很滑稽,但现实又何尝不是这样呢?
  2. Azure Machine Learning Studio 实例 -- 预测xx年的食物工厂总数
  3. SparkCore:RDD累加器和广播变量(最详细的介绍)!!!!!!
  4. 腾讯视频投屏显示无法连接服务器,腾讯视频投屏不能快进
  5. AutomatorX自动化测试工具介绍(Android篇)
  6. IE浏览器退役,终究还是被市场淘汰!
  7. Loadrunner11安装及globa-10000配置
  8. pintia计算机课程考试多选题,大学计算机基础与应用2(理)-中国大学mooc-题库零氪...
  9. 解决Chrome自带翻译功能无法使用问题
  10. 【前端CSS】offsetLeft,Left,clientLeft的区别