简体   繁体   English

jqGrid-PHP / mySQL(遗漏了什么?)

[英]jqGrid - PHP/mySQL (Missed something?)

PHP Code: PHP代码:

$Re = $ZD -> query($PullSearchInfoSQL);
$Rn = $ZD -> found_rows;
if($Rn > 0 && $limit > 0){$Rn = ceil($Rn/$limit);}else{$Rn = 0;}
if($page > $Rn) $page = $Rn;
$start = $limit * $page - $limit;
$Re = $ZD -> query($PullSearchInfoSQL.' LIMIT '.$start.','.$limit);
while($Ro = $ZD -> fetch_assoc($Re)){
    $PullSearchInfoData[] = array('X' => Coords($Ro['SCFieldID']),'P' => $Ro['SCPlayer'],'C' => $Ro['SCCastle'],'F' => $Ro['SCFlag'],'A' => $Ro['SCAlliance'],'S' => PlayerStatus($Ro['SCStatus']),'D' => $Ro['SCSnapA']);
}
$PullSearchInfoData = array('page' => $page,'num' => $Rn,'cell' => $PullSearchInfoData);
echo json_encode($PullSearchInfoData);

jqGrid: jqGrid:

$('#PlayerInformation').jqGrid({
                    url: DateFile+'Data.php?Load=PullSearchInfo&MOpt='+MOpt+'&Data='+$('#SearchThis').val()+'&Parm='+$('#SearchOption').val().split('^')[0]+'&Opts='+$('#SearchOption').val().split('^')[1],
                    datatype:'json',
                    colModel:[
                        {label:'X , Y',name:'X',width:44,align:'left',sortable:false},
                        {label:'Player',name:'P',width:68,align:'left',sortable:false},
                        {label:'Castle',name:'C',width:68,align:'left',sortable:false},
                        {label:'Flag',name:'F',width:28,align:'left',sortable:false},
                        {label:'Alliance',name:'A',width:68,align:'left',sortable:false},
                        {label:'S',name:'S',width:10,align:'center',sortable:false},
                        {label:'Date',name:'D',width:77,align:'center',sortable:false}
                    ],
                    rowNum:1000, altRows:true, height:507, pager:'#PlayerInfoPager',
                    loadComplete: function(){
                            $('#AllPlaTitle').empty().html('History for [ '+$('#SearchThis').val()+ ' ] '+$(this).jqGrid('getGridParam','reccount')+' Listed');
                            $('#PlayerInformation').highlight($('#SearchThis').val(),true);
                            $('#SearchGo,#SearchHist').show();
                            $('#SearchOption,#SearchThis').removeAttr('disabled');
                    }
                });

Database Query Result: 数据库查询结果:

{"page":"1","num":1,"cell":[{"X":"104,135","P":"Gaia of Vansterdam","C":"Hamster","F":"XXX","A":null,"S":"P","D":"01\/07\/15 13:08"},{"X":"102,115","P":"Gaia of Vansterdam","C":"Vansterdam","F":"XXX","A":null,"S":"P","D":"01\/07\/15 13:08"},{"X":"301,3","P":"VonVander","C":"VV1","F":"Von","A":"g144","S":"P","D":"01\/07\/15 13:08"}]}

Before adding page/num to the JSON, everything was working fine. 在将页面/数字添加到JSON之前,一切工作正常。 Until I added page/num, followed instruction on the jqGRID site, I can't for the life outta me figure out why the data is not displaying on the grid. 直到我在jqGRID站点上添加页面/编号并按照说明进行操作,我才能终生弄清楚为什么数据未显示在网格上。 Was my JSON output wrong? 我的JSON输出错误吗? Was my PHP layout incorrect? 我的PHP布局不正确吗?

Thanks for your help in advance! 谢谢您的帮助! Sean 肖恩

I've found my flaw and based on what Barmar suggested, see above post, all is correct, only fixed below: 我发现了自己的缺点,并根据Barmar的建议(请参阅上面的帖子),所有内容都是正确的,仅在下面进行了修复:

Fixed mySQL: 修复了mySQL:

    $count = $ZD -> found_rows;
    if($count > 0 && $limit > 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;

and Array method: 和数组方法:

$PullSearchInfoData = array('total' => (int)$total_pages,'page' => (int)$page,'records' => (int)$count,'rows' => $PullSearchInfoData);

Got the result I was looking for and pulls all the data properly into the jqGRID :) Thanks for helping Barmar! 得到了我一直在寻找的结果,并将所有数据正确地放入jqGRID :)感谢您对Barmar的帮助! Sean 肖恩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM