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 Quote 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. Quote 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 />' ; } ?> Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.