Solved

Display only the latest result from the rss

Posted on 2011-03-02
1
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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 look for a specific file type in a local or remote server directory using PHP.

734 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