PDO PHP中的分页 [英] Pagination in PDO PHP

查看:95
本文介绍了PDO PHP中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图通过PHP/PDO学习分页.

im trying to learn pagination with PHP/PDO.

            $limit = 20;
            $sth = $conn->prepare("SELECT * FROM directory WHERE user_active != ''");
            $sth->execute(array(':county' => $county));

            $c = 1;
            while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
                echo 'Resutls will be here';
            $c++;
            }

我不确定下一步该怎么做,是否有人可以作为我的最佳起点,或者可以为我解释过程?

Im unsure what to do next though, has anybody a good starting point I can reference from, or can explain the process for me?

谢谢

推荐答案

未测试

$page  = 1;
$limit = 20;
$start = $page * $limit;

$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$sth = $conn->prepare("SELECT * FROM directory WHERE user_active LIMIT ?,?");
$sth->execute(array($start,$limit));

这篇关于PDO PHP中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆