Solved

Display only the latest result from the rss

Posted on 2011-03-02
1
280 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

20 Experts available now in Live!

Get 1:1 Help Now