Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display only the latest result from the rss

Posted on 2011-03-02
1
Medium Priority
?
287 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

721 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