Issue with PHP Loop Record not Inserting -


i trying insert records mysql database tables using simple html dom.

checkout codes..

<?php $startpage=1; $endpage=2; for($p=$startpage;$p<=$endpage;$p++) {     $html = file_get_html("http://examplesite.com/index.php?page=$p");      // connect main page links     foreach($html->find('div.tt-name a[1]') $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') $title2)          {             $title[] = $conn->real_escape_string(trim($tit2));         }          foreach($linkhtml->find('div.torrentinfo table tr[3]') $size2)          {                            $size[] = $conn->real_escape_string(trim($size2));                   }          $qv = $conn->query("insert data (title, size, url) values('$title[$i]', '$size[$i]', '$url[$i]')");         if($qv){print "<br>record inserted..!!";}         else {print "<br>".$conn->error;}         $i++;      } }         ?> 

everything working fine problem $url[] on line 11 not inserting records, inserting first record. guess not inside loop, how fix this?

just put $i=0 out of loop , fix incrementing of x $i++


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -