所以我一直在研究下面的代码,无论我做什么,它都不会显示超过当前数据库 *=(来自 URL http://www.example.com/blogs/1)
我希望它显示最后两个或我在顶部参数中放入的多个。
我尝试将"来自博客的故事 ID"与"来自博客的 *"切换都有效,但我试图做的事情也不起作用。我有两个博客条目,它只返回博客条目 1。
<?php
$sql2="select top 2 storyid from Blogs order by storyid desc";
//echo "$sql<br/>";
$results2=mysql_query($sql,$connection);
while ($result=mysql_fetch_assoc($results2)){
$title=$result["Title"];
$storyid=$result["storyid"];
$photo2=$result["Photo2"];
$date=$result["Date"];
?>
<li>
<img src="/images/<?php echo $photo2; ?>" alt="Blog link" />
<div class="blog-details">
<h4><a href="/blogs/<?php echo "$storyid"; ?>"><?php echo "$title"; ?></a></h4>
<p><?php print date('M d Y', strtotime($date)); ?> - <a href="#">2 Comments</a></p>
<li>
<img src="/images/<?php echo $photo2; ?>" alt="Blog link" />
<div class="blog-details">
<h4><a href="/blogs/<?php echo "$storyid"; ?>"><?php echo "$title"; ?></a></h4>
<p><?php print date('M d Y', strtotime($date)); ?> - <a href="#">2 Comments</a></p>
<?php
}
?>
对于MySQL,你必须使用LIMIT而不是TOP。看看这是否有效。
尝试修改查询以使用限制而不是顶部
SELECT storyid FROM Blogs ORDER BY storyid DESC LIMIT 0,2