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?