Jump to content

[SOLVED] Limit number of news displayed


andreea

Recommended Posts

This sequence displays news in a table...How can I limit the number of news displayed? Let's say that i want only 5 records on my page.

Please help! :)

Thanks!

 

 

    <?php

      $list = getNewsList();

      foreach ($list as $value) {

      $newsData = file("news/".$value);

      $newsNivel  = $newsData[0];

$newsLocatie = $newsData[1];

$newsDate = $newsData[2];

$newsInscriere = $newsData[3];

 

      echo "<table align=\"center\" width=\"75%\" border=\"1\"><tr><td width=\"25%\">{$newsNivel}</td>

    <td width=\"25%\">{$newsLocatie}</td>

    <td width=\"15%\">{$newsDate}</td>

    <td width=\"15%\">{$newsInscriere}</td>

 

<td width=\"10%\"><a href=\"delete.php?id=$value\">Sterge</a></td>";

 

      }

 

?>

Link to comment
https://forums.phpfreaks.com/topic/162222-solved-limit-number-of-news-displayed/
Share on other sites

I see, I should have payed more attention, sorry about that.

 

This code should work.

<?php
$list     = getNewsList();
$i = 0;
foreach ($list as $i=>$value) 
{
    while ($i < 5) 
    {
        $newsData         = file("news/".$value);
        $newsNivel      = $newsData[0];
        $newsLocatie     = $newsData[1];
        $newsDate         = $newsData[2];
        $newsInscriere    = $newsData[3];
       
        echo "<table align=\"center\" width=\"75%\" border=\"1\"><tr><td width=\"25%\">{$newsNivel}</td>
                                         <td width=\"25%\">{$newsLocatie}</td>
                                          <td width=\"15%\">{$newsDate}</td>
                                          <td width=\"15%\">{$newsInscriere}</td>
                                        <td width=\"10%\"><a href=\"delete.php?id=$value\">Sterge</a></td>
                ";
    }
    $i++;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.