Help "PHP Warning: Invalid argument supplied for foreach()"

Discussion in 'PHP' started by weezee, Jun 23, 2011.

  1. #1
    I'm getting this error on three lines of my stript.

    1. foreach($keywordsXML->PopularSearchResult as $item) {
    $topicsString = $item->AlternativeSearches;
    $relatedString = $item->RelatedSearches;
    if (!empty($topicsString)) {
    $topics = split(";",$topicsString);


    2. foreach ($xml->channel->item as $item) {
    $ebayRss = $item->children'http://www.domain.com');



    3. foreach ($guidesXML->guide as $guideXML) {
    $guide = array();
    $guide['url'] = makeguideLink($guideXML->url, $q);
    $guide['title'] = $guideXML->title;
    $guide['desc'] = $guideXML->desc;
    array_push($guides,$guide);
     
    weezee, Jun 23, 2011 IP
  2. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #2
    foreach works with array.
    Store your nodes in an array first then pass that array in foreach.. See if that works.
     
    The Webby, Jun 23, 2011 IP
  3. weezee

    weezee Greenhorn

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    I didn't design the stript, someone upgraded the stript for me, but they don't have time to debug it. They have it on a test site, the test site needs to get traffic before the errors show up. I'm not a designer, I thought it maybe something simple I could get help with.
     
    weezee, Jun 23, 2011 IP
  4. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #4
    That's weird, did you hire him,or he just helped you?
    You have to check the node references you are passing to foreach are indeed arrays and not null references. Makes any sense?
     
    The Webby, Jun 23, 2011 IP
  5. weezee

    weezee Greenhorn

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #5
    Don't make any sense to me, don't know any thing about this type of stuff. And no I did not hire him, he just helped, but don't see the errors on his test site because it don't get traffic.
     
    weezee, Jun 23, 2011 IP
  6. weezee

    weezee Greenhorn

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    Oh yes this is the old mcjiffy stript he upgraded for some of the users.
     
    weezee, Jun 23, 2011 IP
  7. vidal

    vidal Well-Known Member

    Messages:
    186
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    145
    #7
    How can I contact the owner of mcjiffy?
     
    vidal, Jun 24, 2012 IP
  8. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #8
    He had time to write the script but no time to test it to see if it worked?
     
    NetStar, Jun 24, 2012 IP
  9. lampChamp

    lampChamp Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Prior to the foreach statement, try to debug the entire object:
    die(var_dump($keywordsXML));
    PHP:
    Copy/paste what it outputs, maybe we could help.
     
    lampChamp, Jun 24, 2012 IP
  10. weezee

    weezee Greenhorn

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #10
    The owner has abandoned the stript and it's no way to contact him. The stript was updated by a user, but the link he left to download the new update is dead. The forum is being taken over by spamers.
     
    weezee, Jun 25, 2012 IP
  11. liquidfire

    liquidfire Greenhorn Affiliate Manager

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #11
    you could always print_r the object to see what it contains
     
    liquidfire, Jun 28, 2012 IP
  12. weezee

    weezee Greenhorn

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #12
    weezee, Jun 29, 2012 IP