Solved

Display only the latest result from the rss

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

732 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