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)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

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

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境