jqGrid - PHP / mySQL(错过了什么?)

时间:2015-01-08 00:43:15

标签: php mysql jqgrid

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:

$('#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');
                    }
                });

数据库查询结果:

{"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"}]}

在将page / num添加到JSON之前,一切正常。直到我添加了page / num,按照jqGRID网站上的说明,我终生无法解决为什么数据没有显示在网格上。我的JSON输出错了吗?我的PHP布局不正确吗?

提前感谢您的帮助! 肖恩

1 个答案:

答案 0 :(得分:0)

我发现了我的缺陷并根据Barmar的建议,见上面的帖子,一切都是正确的,只有在下面修正:

修正了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;

和数组方法:

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

得到了我想要的结果并将所有数据正确地提取到jqGRID :) 谢谢你帮助巴马! 肖恩