我遇到了分页问题。我已经尽可能地调试了,似乎 SELECT 查询和执行存在问题。如果我取出分页部分,查询将执行并在一个长表中显示所有条目。我尝试执行一个数组、bindValue 和 bindParam 但没有任何效果,任何人都可以看到我缺少什么吗?
function showEmployees() {
$count = $this->dbh->query("SELECT * FROM employee_info");
$count->rowCount();
$count = $count->rowCount();
// if ($count > 0) {
// echo "The total amount of employees is " . $count;
// } else {
// echo "There are no records in this table.";
// }
$page_rows = 10;
$last_page = ceil($count / $page_rows);
echo $last_page;
if ($last_page < 1) {
$last_page = 1;
}
$page_num = 10;
if (isset($_GET['pn'])) {
$page_num = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($page_num < 1) {
$page_num = 1;
} elseif ($page_num > $last_page) {
$page_num = $last_page;
}
$limit = 'LIMIT ' .($page_num -1) * $page_rows .', '. $page_rows;
$query = $this->dbh->prepare("SELECT * FROM employee_info ORDER BY employee_id DESC :page_limit");
$query->bindParam(':page_limit', $limit );
$query->execute();
$t = "<table name='displayEmployees' border='1' >";
$t .="<tr>";
$t .= "<th>Employee ID</th>";
$t .= "<th>First Name</th>";
$t .= "<th>Last Name</th>";
$t .= "</tr>";
while($u = $query->fetch(PDO::FETCH_ASSOC)) {
$t .="<tr>";
$t .= "<td>{$u['employee_id']}</td>";
$t .= "<td>{$u['first_name']}</td>";
$t .= "<td>{$u['last_name']}</td>";
$t .="</tr>";
}
$t .="</table>";
return $t;
}