我正在尝试编写一个小小的寻呼系统,但就目前情况而言,我遇到了一个错误。这是我的代码:寻呼和错误
<!-- something before that's working well -->
else{
include('head.php');
if(empty($_GET['pg'])){ $_GET['pg'] = 0 ;}
$offset = $_GET['pg'] * 5;
$query = $db->prepare('SELECT * FROM posts ORDER BY id DESC LIMIT 5 OFFSET :n');
$query->bindParam(':n', $offset);
$query->execute();
?>
<body>
<?php
while ($data = $query->fetch()){
echo '<article>'.$data['content'].'</article>';
}}?>
</body>
所以我只是想显示5页的文章。也就是说,我想索引页上的最后5篇文章(即第0页),则第1页等对未来5篇到目前为止,我得到这个错误是:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0'' at line 1' in /Applications/MAMP/htdocs/index.php:24 Stack trace: #0 /Applications/MAMP/htdocs/index.php(24): PDOStatement->execute() #1 {main} thrown in /Applications/MAMP/htdocs/index.php on line 24
第24行是$query->execute();
指令。
所以我想我的问题是:发生了什么事?我的分页系统是否按照我想要的方式工作?
没有,同样的错误,就像在开始时一样... –