0

I have this code:

<?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 } ?>

and basically, I'm trying to make it show 3 news posts, but it shows the same one, do you guys know what it is that I'm doing wrong in the SQL?

This is what it shows: http://screencloud.net/v/5ENE

I have more than 3 articles in the database, but it's showing the 1 3 times.. Can you guys help?

4

1 回答 1

5

You're mixing two different API's.

You need to reference $row not $array. Something like:

while ($row = $db->assoc($get_news)) {
?>
           <div class="blue box">
             <div class="title"><?php echo $row['title'];?></div>
<?php
}
于 2013-03-15T02:11:19.793 回答