Maison  >  Article  >  développement back-end  >  jqgrid显示不了数据

jqgrid显示不了数据

WBOY
WBOYoriginal
2016-06-23 13:49:361244parcourir

jqgrid显示不数据,请各位大大帮忙看看

<!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" /><title>无标题文档</title><link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" /><link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" /><script src="js/jquery-1.9.0.min.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 type="text/javascript">$(function(){ jQuery("#list").jqGrid({   	url:'dd.php',	datatype: "json",	height: 255,	width: 600,   	colNames:['编号','名称','主屏尺寸','操作系统','电池容量', '价格(¥)','操作'], //数据列名称(数组)   	colModel:[ //数据列各参数信息设置   		{name:'sn',index:'sn', editable:true, width:80,align:'center',title:false,editable: true,edittype:"text"},   		{name:'title',index:'title', width:180,title:false, editable: true,sorttype:"text"},   		{name:'size',index:'size', width:120, editable: true,sorttype:"text"},		{name:'os',index:'os', width:120,editable:true,sorttype:"text"},   		{name:'charge',index:'charge', width:100,align:'center',editable:true,sorttype:"text"},		{name:'price',index:'price', width:80,align:'center',editable:true,sorttype:"text"},   		{name:'opt',index:'opt', width:80, sortable:false, align:'center',editable:true,sorttype:"text"}		   	],   	rowNum:50,	rowTotal: 2000,	rowList : [20,30,50],	loadonce:true,   	mtype: "GET",	rownumbers: true,	rownumWidth: 40,	gridview: true,   	pager: '#pager',   	sortname: 'id',    viewrecords: true,    sortorder: "asc",	caption: "Toolbar Searching"	});jQuery("#list").jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:false});jQuery("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});  }); </script></head><body><table id="list"></table><div id="page" ></div></body></html>


<?PHPinclude_once ("connect.php");	$page = $_GET['page'];		$limit = $_GET['rows'];		$sidx = $_GET['sidx'];		$sord = $_GET['sord'];		if (!$sidx)			$sidx = 1;        $where = '';        $title = uniDecode($_GET['title'],'utf-8');        if(!empty($title))            $where .= " and title like '%".$title."%'";        $sn = uniDecode($_GET['sn'],'utf-8');        if(!empty($sn))            $where .= " and sn='$sn'";		$result = mysql_query("SELECT COUNT(*) AS count FROM products where deleted=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 products WHERE deleted=0".$where." ORDER BY $sidx $sord LIMIT $start , $limit";		$result = mysql_query($SQL) or die("Couldn t execute query." . mysql_error());		$responce->page = $page;		$responce->total = $total_pages;		$responce->records = $count;		$i = 0;		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {			$responce->rows[$i]['id'] = $row[id];			$opt = "<a href='#'>修改</a>";			$responce->rows[$i]['cell'] = array (				$row['sn'],				$row['title'],				$row['size'],				$row['os'],				$row['charge'],				$row['price'],				$opt			);			$i++;		}		//print_r($responce);		echo json_encode($responce);								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;}?>


回复讨论(解决方案)

$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/", toUtf8, $str);
应为
$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/", 'toUtf8', $str);

xuzuning大大, 'toUtf8'加两个单引号,我加了不行,我不知道是不是文件的编码有问题,本地测试的时候,有些Js文件我改一下编码,就显不了数据库的数据了

另外我直接输出结果


<?phpinclude_once ("connect.php");			$page = 1;	$limit = 12;	$sidx = 'id';		$sord = 'asc';		if (!$sidx)			$sidx = 1;        $where = '';        $title = "";        if(!empty($title))            $where .= " and title like '%".$title."%'";        $sn = "";        if(!empty($sn))            $where .= " and sn='$sn'";		$result = mysql_query("SELECT COUNT(*) AS count FROM products where deleted=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 products WHERE deleted=0".$where." ORDER BY $sidx $sord LIMIT $start , $limit";		$result = mysql_query($SQL) or die("Couldn t execute query." . mysql_error());		$responce->page = $page;		$responce->total = $total_pages;		$responce->records = $count;		$i = 0;		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {			$responce->rows[$i]['id'] = $row["id"];			$opt = "<a href='#'>修改</a>";			$responce->rows[$i]['cell'] = array ($row['sn'],$row['title'],$row['size'],	$row['os'],	$row['charge'],	$row['price'],$opt);			$i++;		}				echo json_encode($responce);?>









{"page":1,"total":2,"records":"14","rows":[{"id":"1","cell":["1001","\u82f9\u679ciPhone 4S\uff0816GB\uff09","3.5\u82f1\u5bf8 960x640\u50cf\u7d20 ","iOS 5.0","1420mAh","5150","\u4fee\u6539<\/a>"]},{"id":"2","cell":["1002","\u4e09\u661fI9100 GALAXY SII\uff0816GB\uff09","4.3\u82f1\u5bf8 800x480\u50cf\u7d20 ","Android OS 2.3 ","1650mAh ","3790","\u4fee\u6539<\/a>"]},{"id":"3","cell":["1003","HTC G11\uff08Incredible S\uff09","4\u82f1\u5bf8 800x480\u50cf\u7d20","Android OS 2.2 ","1450mAh","2232","\u4fee\u6539<\/a>"]},{"id":"4","cell":["1004","\u9b45\u65cfM9\uff088GB\uff09","3.5\u82f1\u5bf8 960x640\u50cf\u7d20","Android OS 2.3 ","1370mAh","1729","\u4fee\u6539<\/a>"]},{"id":"5","cell":["1005","\u5c0f\u7c73M1\uff08MIUI\uff09","4\u82f1\u5bf8 854x480\u50cf\u7d20","MIUI+\u539f\u751fAndroid","1930mAh","1999","\u4fee\u6539<\/a>"]},{"id":"6","cell":["1006","\u8bfa\u57fa\u4e9aC5-03","3.2\u82f1\u5bf8 640x360\u50cf\u7d20 ","Symbian S60V5","1000mAh","1164","\u4fee\u6539<\/a>"]},{"id":"7","cell":["1007","\u6469\u6258\u7f57\u62c9XT910\uff08DROID RAZR\uff09","4.3\u82f1\u5bf8 960x540\u50cf\u7d20 ","Android OS 2.3 ","1780mAh","3700","\u4fee\u6539<\/a>"]},{"id":"8","cell":["1008","\u8bfa\u57fa\u4e9aN8","3.5\u82f1\u5bf8 640x360\u50cf\u7d20 ","Symbian^3 ","1200mAh","2302","\u4fee\u6539<\/a>"]},{"id":"9","cell":["1009","\u534e\u4e3aU8860 Honor\uff08\u8363\u8000\uff09","4\u82f1\u5bf8 854x480\u50cf\u7d20","Android OS 2.3","1930mAh","1889","\u4fee\u6539<\/a>"]},{"id":"10","cell":["1010","\u4e09\u661fW999","3.5\u82f1\u5bf8 800x480\u50cf","Android OS 2.3 ","1500mAh ","12340","\u4fee\u6539<\/a>"]},{"id":"11","cell":["1011","\u9177\u6d3eN900+","3.2\u82f1\u5bf8 480x320\u50cf ","Windows CE 6.0 ","1500mAh ","6180","\u4fee\u6539<\/a>"]},{"id":"12","cell":["1012","\u9ed1\u83939800\uff08Torch\uff09","3.2\u82f1\u5bf8 480x360\u50cf\u7d20","BlackBerry OS 6","1300mAh","4900","\u4fee\u6539<\/a>"]}]}

可以显示了,我把那些转换函数都删除了

请参考jqGrid中文demo:http://blog.mn886.net/jqGrid/

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:tkinkphp查询总是出现怪问题Article suivant:PHP 删除文件