Solved

Display only the latest result from the rss

Posted on 2011-03-02
1
281 Views
Last Modified: 2012-05-11
Hey All,

I have a rss feed which is currently showing 20+ summaries and I only want to show the latest summary (so only ever 1 article).

Here is the code which I am using:
$nid = "foxmain";
				$need_url="http://feeds.news.com.au/public/rss/2.0/fs_breaking_news_13.xml";
				$provider = "Fox Sports";
				$i=0;
				$doc = new DOMDocument();
				$doc->load($need_url);
				$employees = $doc->getElementsByTagName("item");
				foreach( $employees as $employee ) {
					$i++;
					$names = $employee->getElementsByTagName("title");
					$name = $names->item(0)->nodeValue;
					$links= $employee->getElementsByTagName("link");
					$link= $links->item(0)->nodeValue;
					$descriptions= $employee->getElementsByTagName("description");
					$description= $descriptions->item(0)->nodeValue;
					echo " <h4>$name</h4>";
					echo "<p>$description</p>";
					echo " <p><a href=$link target='_blank'><strong>&raquo; More</strong></a> &nbsp; ";
				
					if($getUserData > 0) {
						echo " <a href='public_create_forum.php?an=".$name."&ad=".$description."'><strong>&raquo; Comment</strong></a></p>";
					} else {
						echo " <a id='view_comment_".$i."' href='#' onclick='getforumdata(".$i.");'><strong>&raquo; Comment</strong></a></p>";
					}
				}

Open in new window


Any ideas on this would be great!

Thanks in advance,
PD!!!
0
Comment
Question by:piixeldesigns
1 Comment
 
LVL 3

Accepted Solution

by:
wwwdeveloper2 earned 500 total points
ID: 35023945
Try this for a quick fix:

 
$need_url="http://feeds.news.com.au/public/rss/2.0/fs_breaking_news_13.xml";
				$provider = "Fox Sports";
				$i=0;
				$doc = new DOMDocument();
				$doc->load($need_url);
				$employees = $doc->getElementsByTagName("item");
				foreach( $employees as $employee ) {
while ($i<'2'){					
$i++;
					$names = $employee->getElementsByTagName("title");
					$name = $names->item(0)->nodeValue;
					$links= $employee->getElementsByTagName("link");
					$link= $links->item(0)->nodeValue;
					$descriptions= $employee->getElementsByTagName("description");
					$description= $descriptions->item(0)->nodeValue;
					echo " <h4>$name</h4>";
					echo "<p>$description</p>";
					echo " <p><a href=$link target='_blank'><strong>&raquo; More</strong></a> &nbsp; ";
				
					if($getUserData > 0) {
						echo " <a href='public_create_forum.php?an=".$name."&ad=".$description."'><strong>&raquo; Comment</strong></a></p>";
					} else {
						echo " <a id='view_comment_".$i."' href='#' onclick='getforumdata(".$i.");'><strong>&raquo; Comment</strong></a></p>";
					}
}
				}

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now