我遇到了分页问题。我已经尽可能地进行了调试,看起来SELECT查询和执行有问题。如果我取出分页部分,查询将执行并显示长表中的所有条目。我尝试执行一个数组,bindValue和bindParam,但没有任何工作,任何人都可以看到我失踪?PHP OOP分页
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;
}
感谢迈克,我明白你在说什么,并欣赏它,由于注射的偏执我有这么多为我准备做不假思索所有发言的习惯,但你是正确的,在这种情况下,这是多余的,抱歉,我还没有被允许投票。 – Jake