douluanzhao6689 2019-05-28 15:05
浏览 68

尝试从pdo查询构建服务器端数据表

I have to build a data table from server side because I have more than 200k rows, and I don't have the choice I need to make it from an execute statement like:

$result['draw']=1;
$temp = BD::query('SELECT * FROM `ersmessages` WHERE 1 LIMIT 10');
$result['recordsTotal'] = sizeof($temp);
$result['recordsFiltered'] = sizeof($temp);
$result['data'] = $temp;

But when I'm doing this that does not page my results and for 200k rows it's giving an error. If I limit the query that works but on one page.

My JS looks like:

 $('#tableAllMessages').DataTable( {
        "processing": true,
        "serverSide": true,
        "paging": true,
        "searching": { "regex": true },
        "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ],
        "pageLength": 10,
        "ajax": "req/getAllMessages.php"
    } );

How should I proceed to have a paged data table with 200k rows? I can't obviously use the ssp.

  • 写回答

1条回答 默认 最新

  • doujiu5464 2019-05-29 08:07
    关注

    ok the problem has been solved, i needed to put the recordsTotal to my maximum(200k rows) size and i needed to add an offset to the query, that way i am able to paginate my table.

    $offset = $_REQUEST['start'];
    $result['recordsTotal'] = 200000;
    $query = BD::query('SELECT * FROM `ersmessages` WHERE 1 ORDER BY `idERSMessage` ASC LIMIT 10 OFFSET '.intval($offset))
    $result['data'] = $query;
    $result['draw']=$_REQUEST['draw'];
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题