gpt4 book ai didi

php - 分页不显示 PHP PDO

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:36 24 4
gpt4 key购买 nike

我试图对我的查询进行分页,但没有任何输出,有人能看出我哪里出错了吗?我是 PHP/PDO 的新手

else {
try
{
$per_page = '3';
$result = $conn->prepare("SELECT * FROM directory WHERE user_active != ''");
$rows = $result ->fetchAll();
$total_records = count($rows);
$pages = ceil($total_records / $per_page);
$page = (isset ($_GET['page'])) ? (int) $_GET['page'] : 1 ;
$start = ($page - 1) * $per_page;
$query = $conn->prepare("SELECT * FROM directory WHERE user_active != ''");
while($row = $query->fetch(PDO::FETCH_ASSOC)){
echo '<br>' . $row['id'] . '<br>' . $row['First_Name'] . '<br>' . $row['Surname'] . '<br>';
} ?>
<br><br>
<?php
if ($pages >= 1 && $page <= $pages){
//if ($page>1 && $page <= $pages){$previous=($page -1); echo '<a href="?page=' .$previous. '">Previous</a>';}
for($x=1; $x<=$pages; $x++){ echo ($x == $page) ? ' <strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : ' <a href="?page='.$x.'">'.$x.'</a> ';}
//if ($page>1 && $page <= $pages){ $next=($page+1) ; echo '<a href="?page=' .$next. '">Next</a>';}
}
####################### Close Database #######################
$db = NULL;
}
catch(PDOException $e)
{
print 'Exception : '.$e->getMessage();
}
};

最佳答案

你永远不会execute查询。

$result->execute();
$rows = $result ->fetchAll();

$query->execute();
while($row = $query->fetch(PDO::FETCH_ASSOC)){

关于php - 分页不显示 PHP PDO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13407763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com