php error, can somebody help

Discussion in 'PHP' started by smetten, Apr 21, 2008.

  1. #1
    Warning: Invalid argument supplied for foreach() in /home/content/s/m/e/smetten/html/phpinfo.php5 on line 15
    this is what´s on line 15: ($rss->channel->item as $item)

    Im experimenting with xml feeds.
    I can get other feeds to work, but this keeps giving me this error...
    Can anyone tell me what i must change

    
    <?php // Load and parse the XML document 
    $rss =  simplexml_load_file('http://api.indeed.com/apisearch?key=17a05830c4a0eb769feb73cfc499050d&q=&l=Wisconsin&sort=date&start=10&limit=100&fromage300=&filter=&latlong=1');
    $title =  $rss->channel->title;
    ?>
    <html xml:lang="en" lang="en">
    <head>
      <title><?php echo $item; ?></title>
    </head>
    <body bgcolor=black link=yellow text=white>
    
    <h1><?php echo $item; ?></h1>
    
    <?php
    // Here we'll put a loop to include each item's title and description
    foreach ($rss->channel->item as $item) 
    {
      echo "<h2><font color=red></font color>&nbsp;&nbsp;<a href='" . $item->url . "'>" . $item->jobtitle . "</a></h2>";
      echo "<p> <font color=red></font color>&nbsp;&nbsp;" . $item->company . "</p>";
      echo "<p> <font color=red></font color>&nbsp;&nbsp;" . $item->city . "</p>";
      }
    ?>
    </body>
    </html>
    
    PHP:
     
    smetten, Apr 21, 2008 IP
  2. nihcer

    nihcer Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    check your rss source (copy the url into a browser and see the xml structure)

    I think what you're trying to do is:

    .
    .
    foreach ($rss->results->result as $item) 
    {
    .
    .
    }
    PHP:
     
    nihcer, Apr 21, 2008 IP
  3. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    thx mate

    that actually worked

    as i said, im just starting out with php :)

    Greetz

    smetten
     
    smetten, Apr 21, 2008 IP