【问题标题】:jqGrid - PHP/mySQL (Missed something?)jqGrid - PHP/mySQL(错过了什么?)
【发布时间】:2015-01-08 00:43:14
【问题描述】:

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 布局不正确吗?

提前感谢您的帮助! 肖恩

【问题讨论】:

  • 您在第一次加载网格时设置了url: 参数,因此您在用户填写字段之前得到$('#SearchThis').val() 之类的内容,而不是在他们修改之后。
  • 如何设置变量$limit$page
  • 哦,你是说回调?

标签: php mysql jqgrid


【解决方案1】:

我发现了我的缺陷,根据 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 :) 感谢您帮助巴尔玛! 肖恩

【讨论】:

    猜你喜欢
    • 2018-10-19
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2014-05-14
    相关资源
    最近更新 更多