我正在尝试创建一个带有变量 LIMIT 值的 MySQL 查询,以在多个页面上显示表结果。这不起作用:
// Check the page number
if (isset($_GET["usPage"])) {
$treatedPage = mysql_real_escape_string(strip_tags($_GET["usPage"]));
} else {
$treatedPage=1;
}
$start_from = ($treatedPage-1) * 20;
// Prepare MySQL query with a variable depending on page to display
$req = $DB->prepare('SELECT * FROM Table ORDER BY Id ASC LIMIT :MySQL_start_from, 20');
$req->execute(array(
'MySQL_start_from' => $start_from
));
// Fetch result and display array content
$row = $req->fetch();
echo '<pre>';
print_r($row);
echo '</pre>';
如果我将 :MySQL_start_from 替换为 0,我可以显示行内容。我认为我的问题来自查询中的那个变量。发现任何错误?