I have been having a problem with my PHP loop described below.
$query1 = "SELECT * FROM volume_issue";
$sql=$con->prepare($query1);
$sql->execute();
while ($row = $sql->fetch()) {
//echo $row['id'] . " ". $row['url']."<br />\n";
$volume_issue_id = $row['id'];
$url = $row['url'];
$volume_issue = $row['volume_issue'];
$html2 = file_get_html($url);
//
//echo $url . '<br>';
$html = file_get_html($url);
foreach($html->find('table[class="tocArticle"]') as $div){
//echo $div->innertext . '<br>';
//echo "<p/>". $div->nodeName. ": ";
foreach($div->find('td[class="tocTitle"]') as $td){
//echo $td . "<br />";
foreach ($td->find('a') as $links){
$url =$links->href;
$title = $links->innertext;
echo $title . '<br>';
$query1 = "INSERT INTO citations_url (title,url) VALUES (:title,:url)";
$sql=$con->prepare($query1);
$sql->execute(array(
':title' => $title,
':url' => $url
));
}
}
}
}
The problem is that this loop is only inserting 20 rows instead of 615. Also, When I remove the MySQL query and echo out $title i get 615 rows. However, when I include the MySQL query and echo out $title i get 20 rows and only 20 rows are inserted.
I have been cracking my head over this one. What might I be doing wrong?
$sql: at the top and in the inner loop. Try renaming the 2-nd to $sql1.