首頁  >  文章  >  後端開發  >  关于jqgrid的问题

关于jqgrid的问题

WBOY
WBOY原創
2016-06-23 14:05:23808瀏覽

关于jqgrid的问题
一。本地测试可以显示数据库数据,上传到服务器上就显示不了,sql都在phpmyadmin测试过,可以用的,请问怎么查是什么原因。

二。编码问题,页面本来编码为GB的,我把sale_list.html和do.php用记事本转成utf-8后,本地测试jqgrid就显示不了数据。

do.php源码

<?phpinclude_once ("conn.php");$action = $_GET['action'];switch ($action) {	case 'list' : //列表		$page = $_GET['page'];		$limit = $_GET['rows'];		$sidx = $_GET['sidx'];		$sord = $_GET['sord'];//		$page = 1;//		$limit = 12;//		$sidx = 'id';//		$sord = 'asc';		if (!$sidx)			$sidx = 1;        $where = '';        $product_name = uniDecode($_GET['product_name'],'utf-8');        if(!empty($product_name))            $where .= " and `product-name` like '%".$product_name."%'";        $order_id = uniDecode($_GET['order_id'],'utf-8');        if(!empty($order_id))           // $where .= " and order_id='$order_id'";             $where .= " and `order_id` like '%".$order_id."%'";		//$result = mysql_query("SELECT COUNT(*) AS count FROM products where deleted=0".$where);		$result = mysql_query("SELECT COUNT(*) AS count FROM `sale_orders` WHERE `number`>0".$where);		$row = mysql_fetch_array($result, MYSQL_ASSOC);		$count = $row['count'];		//echo $count;		if ($count > 0) {			$total_pages = ceil($count / $limit);		} else {			$total_pages = 0;		}		if ($page > $total_pages)			$page = $total_pages;		$start = $limit * $page - $limit;		if ($start<0) $start = 0;		$SQL = "SELECT * FROM `sale_orders` WHERE `number`>0".$where." ORDER BY $sidx $sord LIMIT $start , $limit";		$result = mysql_query($SQL);		$responce->page = $page;		$responce->total = $total_pages;		$responce->records = $count;		$i = 0;		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {			$responce->rows[$i]['order_id'] = $row['order_id'];			$opt = "<a href='#'>修改</a>";			$responce->rows[$i]['cell'] = array (				$row['order_id'],				$row['buyer-name'],				$row['jj_sku'],				$row['sku'],				$row['product-name'],				$row['quantity-purchased'],				$opt			);			$i++;		}		//print_r($responce);		echo json_encode($responce);		break;	case 'add' : //新增		$pro_title = htmlspecialchars(stripslashes(trim($_POST['pro_title'])));		$pro_sn = htmlspecialchars(stripslashes(trim($_POST['pro_sn'])));		$size = htmlspecialchars(stripslashes(trim($_POST['size'])));		$os = htmlspecialchars(stripslashes(trim($_POST['os'])));		$charge = htmlspecialchars(stripslashes(trim($_POST['charge'])));		$price = htmlspecialchars(stripslashes(trim($_POST['price'])));		if (mb_strlen($pro_title) < 1)			die("产品名称不能为空");		$addtime = date('Y-m-d H:i:s');		$query = mysql_query("insert into products(sn,title,size,os,charge,price,addtime)values('$pro_sn','$pro_title','$size','$os','$charge','$price','$addtime')");		if (mysql_affected_rows($conn) != 1) {			die("操作失败");		} else {			echo '1';		}		break;	case 'del' : //删除		$ids = $_POST['ids'];		delAllSelect($ids, $conn);		break;	case '' :		echo 'Bad request.';		break;}//批量删除操作function delAllSelect($ids, $conn) {	if (empty ($ids))		die("0");	//mysql_query("update products set deleted=1 where id in($ids)");		mysql_query("delete FROM `sale_orders` WHERE order_id='$ids'");	if (mysql_affected_rows($conn)) {		echo $ids;	} else {		die("0");	}}//处理接收jqGrid提交查询的中文字符串function uniDecode($str, $charcode) {	$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/", toUtf8, $str);	return mb_convert_encoding($text, $charcode, 'utf-8');}function toUtf8($ar) {	foreach ($ar as $val) {		$val = intval(substr($val, 2), 16);		if ($val < 0x7F) { // 0000-007F			$c .= chr($val);		}		elseif ($val < 0x800) { // 0080-0800			$c .= chr(0xC0 | ($val / 64));			$c .= chr(0x80 | ($val % 64));		} else { // 0800-FFFF			$c .= chr(0xE0 | (($val / 64) / 64));			$c .= chr(0x80 | (($val / 64) % 64));			$c .= chr(0x80 | ($val % 64));		}	}	return $c;}echo $page;echo $limit;echo $sidx;echo $sord;?>


回复讨论(解决方案)

楼主的数据库编码是什么呀,必须和页面统一哦。

qGrid 是一个用来显示网格数据的jQuery插件
传递给他的数据应该是 json,你就简单的
echo $page;
echo $limit;
echo $sidx;
echo $sord;
算什么?

echo $page;
echo $limit;
echo $sidx;
echo $sord;
因为后面两个变更我不知道什么意思,所以想输出一下看看
sale_list.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="keywords" content="jNotify, jquery插件" /><meta name="description" content="Helloweba演示平台,演示XHTML、CSS、jquery、PHP案例和示例" /><title>jqGrid:强大的表格插件的应用-Helloweba演示平台</title><!--<link rel="stylesheet" type="text/css" href="/css/main.css" />--><link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" /><link rel="stylesheet" type="text/css" href="css/ui.jqgrid.css" /><link rel="stylesheet" type="text/css" href="css/style.css" /><script src="js/jquery.js" type="text/javascript"></script><script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script><script src="js/jquery.jqGrid.min.js" type="text/javascript"></script><script src="js/jquery.fancybox.js" type="text/javascript"></script><script src="js/jquery.message.js" type="text/javascript"></script><link rel="stylesheet" type="text/css" href="css/fancybox.css" /><style type="text/css"><!--body {	background-color: #FFFFFF;}--></style></head><body><div id="main"><h2 class="top_title">销售订单列表</h2><div class="grid_table">     <div id="opt">        <div id="query">            <label>订单号:</label>   <input type="text" class="input" id="order_id" />            <label>产品名称:</label>  <input type="text" class="input" id="product_name" />            <input type="submit" class="btn" id="find_btn" value="查 询" />        </div>        <input type="button" class="btn" id="add_btn" value="新 增" />        <input type="button" class="btn" id="del_btn" value="删 除" />     </div>     <table id="list"></table>     <div id="pager"></div></div><div class="google_ad"><script type="text/javascript">google_ad_client = "ca-pub-7515443544894528";google_ad_slot = "3438097725";google_ad_width = 728;google_ad_height = 90;</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div></div><script type="text/javascript">$("#list").jqGrid({	url:'do.php?action=list',  //请求数据的url地址	datatype: "json",  //请求的数据类型   	colNames:['订单号','客户姓名','标准SKU','订单SKU','产品名称', '购买数量','操作'], //数据列名称(数组)   	colModel:[ //数据列各参数信息设置   		{name:'order_id',index:'order_id', editable:true, width:80,align:'center', title:false},   		{name:'buyer-name',index:'buyer-name', width:180, title:false},   		{name:'jj_sku',index:'jj_sku', width:120},		{name:'sku',index:'sku', width:120},   		{name:'product-name',index:'product-name', width:100,align:'center'},		{name:'quantity-purchased',index:'price', width:80,align:'center'},   		{name:'opt',index:'opt', width:80, sortable:false, align:'center'}						   	],   	rowNum:10, //每页显示记录数   	rowList:[10,20,30], //分页选项,可以下拉选择每页显示记录数   	pager: '#pager',  //表格数据关联的分页条,html元素	autowidth: true, //自动匹配宽度	height:275,   //设置高度	gridview:true, //加速显示    viewrecords: true,  //显示总记录数	multiselect: true,  //可多选,出现多选框	multiselectWidth: 25, //设置多选列宽度	sortable:true,  //可以排序	sortname: 'order_id',  //排序字段名    sortorder: "desc", //排序方式:倒序,本例中设置默认按id倒序排序	loadComplete:function(data){ //完成服务器请求后,回调函数		if(data.records==0){ //如果没有记录返回,追加提示信息,删除按钮不可用			$("p").appendTo($("#list")).addClass("nodata").html('找不到相关数据!');			$("#del_btn").attr("disabled",true);		}else{ //否则,删除提示,删除按钮可用			$("p.nodata").remove();			$("#del_btn").removeAttr("disabled");		}	} });$(function(){	$("#add_btn").click(function(){		$.fancybox({			'type':'ajax',			'href':'aaaddGrid.html'		});	});	$("#del_btn").click(function(){		var sels = $("#list").jqGrid('getGridParam','selarrrow');	    if(sels==""){		   alert('请选择要删除的项!')	    }else{		   if(confirm("您是否确认删除?")){		    $.ajax({              type: "POST",              url: "do.php?action=del",			  data: "ids="+sels,			  beforeSend: function() {                   $().message("正在请求...");              },			  error:function(){				   $().message("请求失败...");			  },              success: function(msg){				   if(msg!=0){					   var arr = msg.split(',');					   $.each(arr,function(i,n){							 if(arr[i]!=""){								 $("#list").jqGrid('delRowData',n); 							 }		               });		               $().message("已成功删除!");				   }else{					   $().message("操作失败!");				   }              }            });	       }	    }	});		$("#find_btn").click(function(){		var product_name = escape($("#product_name").val());	    var order_id = escape($("#order_id").val());	    $("#list").jqGrid('setGridParam',{			url:"do.php?action=list",			postData:{'product_name':product_name,'order_id':order_id},			page:1		}).trigger("reloadGrid");	});});</script></body></html>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn