简体   繁体   中英

jqGrid - PHP/mySQL (Missed something?)

PHP Code:

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

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. 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. Was my JSON output wrong? Was my PHP layout incorrect?

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:

Fixed 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! Sean

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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