mme Posted December 4, 2008 Share Posted December 4, 2008 Hi I would like to make it only display 3 entries how would I do this? <?php require_once 'rss/rss_fetch.inc'; $url = 'http://mysite.com/rss' ; $rss = fetch_rss($url); if ( $rss and !$rss->ERROR) { foreach ($rss->items as $item ) { echo ' <p><a href="' . $item[link] . '" target="_blank"><b>' . $item[title] . '</b></a><br / >'; echo '<i>Publish Date: ' . $item[pubdate] . '</i><br / >'; echo $item[ description ] . ' </p>' ; } } else { echo '<b>RSS Error: ' . $rss->ERROR . ' </b><br / ><br />' ; } ?> Thanks Link to comment https://forums.phpfreaks.com/topic/135564-solved-rss-only-displaying-3/ Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 <?php require_once 'rss/rss_fetch.inc'; $url = 'http://mysite.com/rss' ; $rss = fetch_rss($url); if ( $rss and !$rss->ERROR) { $i=0; foreach ($rss->items as $item ) { if ($i > 2) break; echo ' <p><a href="' . $item[link] . '" target="_blank"><b>' . $item[title] . '</b></a><br / >'; echo '<i>Publish Date: ' . $item[pubdate] . '</i><br / >'; echo $item[ description ] . ' </p>' ; $i++; } } else { echo '<b>RSS Error: ' . $rss->ERROR . ' </b><br / ><br />' ; } ?> Should work. Another variation is: <?php require_once 'rss/rss_fetch.inc'; $url = 'http://mysite.com/rss' ; $rss = fetch_rss($url); if ( $rss and !$rss->ERROR) { for($i=0; $i < 3; $i++) { $item = $rss->items[$i]; echo ' <p><a href="' . $item[link] . '" target="_blank"><b>' . $item[title] . '</b></a><br / >'; echo '<i>Publish Date: ' . $item[pubdate] . '</i><br / >'; echo $item[ description ] . ' </p>' ; } } else { echo '<b>RSS Error: ' . $rss->ERROR . ' </b><br / ><br />' ; } ?> That might be more preferred but yea. Link to comment https://forums.phpfreaks.com/topic/135564-solved-rss-only-displaying-3/#findComment-706226 Share on other sites More sharing options...
flyhoney Posted December 4, 2008 Share Posted December 4, 2008 <?php require_once 'rss/rss_fetch.inc'; $url = 'http://mysite.com/rss' ; $rss = fetch_rss($url); if ( $rss and !$rss->ERROR) { for ($x = 0; $x < 3; $x++) { $item = $rss->items[$x]; echo ' <p><a href="' . $item[link] . '" target="_blank"><b>' . $item[title] . '</b></a><br / >'; echo '<i>Publish Date: ' . $item[pubdate] . '</i><br / >'; echo $item[ description ] . ' </p>' ; } } else { echo '<b>RSS Error: ' . $rss->ERROR . ' </b><br / ><br />' ; } ?> Link to comment https://forums.phpfreaks.com/topic/135564-solved-rss-only-displaying-3/#findComment-706230 Share on other sites More sharing options...
mme Posted December 4, 2008 Author Share Posted December 4, 2008 Thanks so much all working now Link to comment https://forums.phpfreaks.com/topic/135564-solved-rss-only-displaying-3/#findComment-706236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.