我有这样的代码:
<?php
$get_news = $db->query("SELECT * FROM news WHERE category = 1 ORDER BY id DESC limit 5");
$array = $db->assoc($get_news);
$num = $db->num($get_news);
if ($num == 0) {
echo "<div class='"title'">No news found!</div>";
}
while($row = mysql_fetch_array($get_news)){
?>
<div class="blue box">
<div class="title"><?php echo $array['title'];?></div>
<div class="content">
<img src="panel/_news/<?php echo $array['image'];?>" style="max-width: 150px;max-height:150px;" alt='"'" align="center">
<div style="margin-top: 14px;">
<div class="readmore">By <?php echo $array['poster'];?></div>
<div class="date"><?php echo $array['date'];?></div>
</div>
</div>
</div>
<?php } ?>
,基本上,我试图让它显示3个新闻帖子,但它显示相同的一个,你们知道这是什么,我在SQL做错了吗?
显示如下:http://screencloud.net/v/5ENE
我有超过3篇文章在数据库中,但它显示13次…你们能帮忙吗?
你混合了两个不同的API。
您需要引用$row
而不是$array
。比如:
while ($row = $db->assoc($get_news)) {
?>
<div class="blue box">
<div class="title"><?php echo $row['title'];?></div>
<?php
}