Home:ALL Converter>Issue with PHP Loop Record not Inserting

Issue with PHP Loop Record not Inserting

Ask Time:2015-09-30T05:23:23         Author:KenDev

Json Formatter

I am trying to insert records into mysql database tables using Simple HTML DOM.

Checkout the codes..

<?php
$startpage=1;
$endpage=2;
for($p=$startpage;$p<=$endpage;$p++)
{
    $html = file_get_html("http://examplesite.com/index.php?page=$p");

    // connect to main page links
    foreach($html->find('div.tt-name a[1]') as $link)
    {   
        $linkHref = $link->href;
        $url[] = $conn->real_escape_string(trim($linkHref));        

        //loop through each link
        $linkHtml = file_get_html('http://examplesite.com'.$linkHref);

        $title=array();
        $size=array();

        foreach($linkHtml->find('div#content h1') as $title2) 
        {
            $title[] = $conn->real_escape_string(trim($tit2));
        }

        foreach($linkHtml->find('div.torrentinfo table tr[3]') as $size2) 
        {               
            $size[] = $conn->real_escape_string(trim($size2));          
        }

        $qv = $conn->query("INSERT INTO data (title, size, url) VALUES('$title[$i]', '$size[$i]', '$url[$i]')");
        if($qv){print "<br>Record Inserted..!!";}
        else {print "<br>".$conn->error;}
        $i++;

    }
}       

?>

Everything is working fine only problem with $url[] on line 11 its not inserting all records, its only inserting first record. I guess its not inside the loop, how to fix this?

Author:KenDev,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32853994/issue-with-php-loop-record-not-inserting
agim :

Just put $i=0 out of the for loop and fix incrementing of x to $i++",
2015-09-29T21:32:57
yy