There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network operating system printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP embedded RSS feed

Reply  
Thread Tools
kineas's Avatar
Computer Specs
Junior Member with 18 posts.
 
Join Date: Jun 2008
30-Oct-2009, 07:28 PM #1
PHP embedded RSS feed
Hi,

So far I have got this code:

PHP Code:
<?

  $feed_url 
"http://www.url.com";

  
$response file_get_contents($feed_url);

  
$xml simplexml_load_string($response); 

  foreach(
$xml->channel->item as $one_item)

  
$i 0;
  while (
$i != 5) {
  echo 
$one_item->title."<BR>";
  
$i++;
  if (
$i == 5) break;
  }


?>
I want it so that it show's the last 5 entries, but that's the best I could do and it's showing the first entry 5 times.

Any help would be great, thanks.

Last edited by kineas; 30-Oct-2009 at 08:42 PM..
maneetpuri's Avatar
Member with 124 posts.
 
Join Date: Oct 2008
31-Oct-2009, 05:14 AM #2
Hi,

If you can first count the number of reco0rds in this file and then set the array pointer to minus 5 position from the total number of records and run the while loop, that should solve your problem.

Hope this helps.

Cheers,
kineas's Avatar
Computer Specs
Junior Member with 18 posts.
 
Join Date: Jun 2008
31-Oct-2009, 06:29 AM #3
Well, I already posted on a different forum because I got bored of waiting, and a guy gave me the exact code I need:

PHP Code:
<?

  $feed_url 
"http://www.url.com";

  
$response file_get_contents($feed_url);

  
$xml simplexml_load_string($response); 

$i 0;
foreach(
$xml->channel->item as $one_item){
   if(
$i 5) {
   echo 
"<TR><TD><BR>"."<a href=".(string)$one_item->link .">".$one_item->title."</A><BR><BR></TD></TR>";
   
$i++;
   }
}
?>
It's what I thought, I had done the loop wrong.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:02 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.