I retrieve a list of filenames from a folder and need to insert it into a mysql database using php.
I insert into the database and it starts building and won't stop. Its only about 20 items in the folder but it keeps looping into database:
<?php
$directory = "/xml/";
$results_array = array();
if(is_dir($directory)) {
if($handle = opendir($directory)){
while(($file = readdir($handle)) !== false) {
$results_array[] = $file;
}
closedir($handle);
}
}
foreach($results_array as $value) {
$e_get = substr($value, 0, 16);
$edate = substr($e_get, -6);
$checkDB = $pdo->query("select `dateString` from `report`");
$checkDB->fetchAll();
foreach($checkDB as $checkItems){
if($checkItems->dateString != $edate) {
$pdo->query("insert into `report`(`dateString`) values
('$edate');
}
}
}
Now I am trying a different way but I only get one item:
<?php
$directory = "/xml/";
$results_array = array();
if(is_dir($directory)) {
if($handle = opendir($directory)){
while(($file = readdir($handle)) !== false) {
$results_array[] = $file;
}
closedir($handle);
}
}
$edate = array();
foreach($results_array as $value) {
$e_get = substr($value, 0, 16);
$edate[] = substr($e_get, -6);
}
foreach($edate as $date) {
$checkDB = $pdo->query("select `dateString` from `report`");
foreach($checkDB as $checkItems) {
if($checkItems->dateString != $date) {
$pdo->query("insert into `report`(`dateString`) values
('$edate');
}
}
}
Please help... Thanks!