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/

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

记事本++7.3.1
好用且免费的代码编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。