我想让值小于我上次的分页值,但我仍然得到空数组,即使应该有值。是我的语法造成这种情况还是我调用这个错误?先谢谢你。试图让值小于使用pdo
<?php
include("connect.php"); //connect to database
//create query
$get_messages_query = $db->prepare("
SELECT * FROM `blogposts`
WHERE `postid` < ?
ORDER BY `postid` DESC
LIMIT 5
");
//Homepage should have last 5 blog posts this will take the
//last 5 entered into the database and put them into an
//array
$one = 1;
$zero = 0;
$lastpage = $_GET['id'];
$pageback = $lastpage - 1;
$pageforward = $lastpage + 1;
$get_messages_query->execute(array($_POST['idid']));
while($row = $get_messages_query->fetch())
{
if($row['comments'] == $one){
$id = $row['postid'];
$blog_post_history .=
'<div class="post" id="post">
<h1>' . $row['title'] .' </h1>
<h2>Written by: ' . $row['author'] . '</h2>
<p>'. $row['content'] . '</p>
<a href="addcomment.php?id='. $row['postid'] .'">Add Comment</a>
<a href="showcomments.php?id='. $row['postid'] . '">Show Comments</a>
<br>
<br>
</div>';
}
else{
$id - $row['postid'];
$blog_post_history .=
'<div class="post" id="post">
<h1>'. $row['title'] .' </h1>
<h2>Written by: ' . $row['author'] . '</h2>
<p>'. $row['content'] . '</p>
<a href="viewblog.php?id='. $row['postid'] .'">View Blog</a>
<br>
<br>
</div>';
}
}
你能告诉你如何试图访问你的结果集吗? – 2013-05-06 16:26:36
添加为喜爱 – Chris 2013-05-06 16:28:41
我看不到这里的分页信息。通常这可以通过做'LIMIT 0,5'(第一页),'LIMIT 5,5'(第二页)等等来执行。所以你在这里有一些复杂的方法。我也不知道你在哪里试图把这些数据放到一个数组中,所以我不完全确定你提到的问题是什么。 – 2013-05-06 16:34:51