andreea Posted June 15, 2009 Share Posted June 15, 2009 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 More sharing options...
trq Posted June 15, 2009 Share Posted June 15, 2009 Assuming getNewsList() executes a database query, put a LIMIT clause in said query. Link to comment https://forums.phpfreaks.com/topic/162222-solved-limit-number-of-news-displayed/#findComment-856127 Share on other sites More sharing options...
Skepsis Posted June 15, 2009 Share Posted June 15, 2009 It's as Thope said. Add a limit clause, this would look like: SELECT name, value FROM table LIMIT 5 Link to comment https://forums.phpfreaks.com/topic/162222-solved-limit-number-of-news-displayed/#findComment-856128 Share on other sites More sharing options...
andreea Posted June 15, 2009 Author Share Posted June 15, 2009 No, I'm not using a database...it's for a very very simple website...the posts are stored in text files in a folder...But thank you anyway Link to comment https://forums.phpfreaks.com/topic/162222-solved-limit-number-of-news-displayed/#findComment-856131 Share on other sites More sharing options...
Skepsis Posted June 15, 2009 Share Posted June 15, 2009 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++; } ?> Link to comment https://forums.phpfreaks.com/topic/162222-solved-limit-number-of-news-displayed/#findComment-856139 Share on other sites More sharing options...
andreea Posted June 15, 2009 Author Share Posted June 15, 2009 For your help. It really worked! Thank you! Link to comment https://forums.phpfreaks.com/topic/162222-solved-limit-number-of-news-displayed/#findComment-856379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.