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?
Thanks
解决方案
not tested
$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));