SimplePie RSS question

I am using SimplePie to display my latest Facebook fan age updates. All works great, however, I cannot get it to limit the list to 1 item.

Here is the code I am using:

<?php
    require_once('rss/rss_fetch.inc');
    $rss = fetch_rss('http://www.facebook.com/feeds/page.php?id=284635508257220&format=rss20');
if(isset($_GET['item']))
{
        $start = $_GET['item'];
        $length = 1;
}
    echo "<a href=".$rss->channel['link']."><strong>".$rss->channel[ 'title']."</strong></a>";
    foreach ($rss->get_items(0, 1) as $item){
    $href = $item['link'];
    $title = $item['title'];
    //$desc = $item['description'];
    echo "<p><a href=$href>$title</a></p>";
    if($desc)
    echo $desc;
    }
    ?>

Anyone know what I am doing wrong?

Geoserv.

Two ways:

Only display the first item in the array (0).




    $items = $rss->get_items(0, 1); 

    // items is now the array of results


    // access only the first one

    $href = $items[0]['link']; 
    $title = $items[0]['title']; 
    // etc
    ?>


Or

Set a counter in case you ever want to change that number from 1 to 2.



$ctr=0;  // set a counter to 0
$target = 1 // set a target number, initially in your case: 1

foreach ($rss->get_items(0, 1) as $item){ 

    if( $ctr < $target ) {  // if the counter is less that your target, go ahead

       $href = $item['link']; 
       $title = $item['title']; 
       //$desc = $item['description']; 
       echo "<p><a href=$href>$title</a></p>"; 
       if($desc) 
       echo $desc; 

       }
    $ctr++;  // iterate the counter
    } 
    ?>

That is not particularly efficient or well written, but should suffice to show you how to limit your array iterations.

You could also use a while ($ctr < $target) loop for example.