PHP Arrays - HELP

Discussion in 'PHP' started by timallard, Jan 24, 2011.

  1. #1
    Hi DP,

    I am working from an example on trying to parse an RSS feed. I can sucessfully parse, but now I want to import into my database. I am very close but my imports are slightly off when importing row by row... here is my example...


    for ($i=0; $i<sizeof($vals); $i++) {
    //Check if the tag type is TITLE and that the value is not the title of your blog

    if ($vals[$i]['tag'] == "GUID" && $vals[$i]['value'] != $blogtitle) {
    echo "<b>Permalink URL:</b><br />";
    echo "<a href=\"" . $vals[$i]['value'] . "\">" . $vals[$i]['value'] . "</a>";
    echo "<br><br>";

    $postiddata = $vals[$i]['value'];
    mysql_query("INSERT INTO rssfeeds (postid) VALUES('$postiddata') ") or die(mysql_error());

    }


    if ($vals[$i]['tag'] == "TITLE" && $vals[$i]['value'] != $blogtitle) {
    echo "<b>Post Title:</b><br />";
    echo $vals[$i]['value'];
    echo "<br><br><hr>";


    //$postiddata = $vals[$i]['value'];
    //$postidval = $vals['tag']['GUID'];
    $posttitledata = $vals[$i]['value'];
    mysql_query("UPDATE rssfeeds SET posttitle='$posttitledata' WHERE postid='$postiddata'") or die(mysql_error());
    }



    }




    when it imports it looks like this

    Post 1 ID ---- Post 2 URL ---- Post 2 Tags
    Post 2 ID ---- Post 3 URL ---- Post 3 Tags
    Post 3 ID ---- Post 4 URL ---- Post 4 Tags

    As you can see I am 1 off in my array...

    I am inserting the first set of url's then going from that url as a unique key.

    Any ideas on how to solve this?

    Thanks!!
     
    timallard, Jan 24, 2011 IP
  2. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    can you post your RSS feed structure please ?
     
    drctaccess, Jan 25, 2011 IP
  3. koula

    koula Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    An advice , don't calculate the number "$i<sizeof($vals)" into the loop because every time than the script returns in this point php does the calculation again and again
    do it like this:

    $num = sizeof($vals);

    for ($i=0; $i<$num; $i++)
     
    koula, Feb 3, 2011 IP