Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Embedded RSS feed help

    Hi guys,

    At the moment, I've 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 
    "<TR><TD bgcolor=\"white\"><FONT face=\"Arial\"><BR>"."<a href=".(string)$one_item->link .">".$one_item->title."</A><BR><BR></TD></TR>";
      
    $i++;
      if (
    $i == 5) break;
      }
    ?>
    I want it so that only the last 5 entries are shown, but the while loop I put in makes it so that it shows the first entry 5 times.

    Any help with this would be great, thanks.
    Last edited by Kineas; 10-31-2009 at 02:39 AM.

  • #2
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts
    *bump*

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,492
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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 bgcolor=\"white\"><FONT face=\"Arial\"><BR>"."<a href=".(string)$one_item->link .">".$one_item->title."</A><BR><BR></TD></TR>";
       
    $i++;
       }
    }
    ?>

  • #4
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thanks a lot, I knew I hadn't done the loop right lol, works perfectly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •