Page 1 of 1

For loop problems...

Posted: Fri Feb 19, 2010 2:59 pm
by emexinc
...i am trying to import information from a .txt file into a mysql database, while at the same time when an if function is met, checking another .txt file and importing information from that file as well into the database...the line of

Code: Select all

if($n == $item_number_1."p"){$poplar = $p;}
when taken out, does not allow the two files to be compared, but at least the information from the first .txt file is all inputed into the database, but when...

Code: Select all

$fh = fopen($myFile, 'r');
$data = fread($fh, filesize($myFile));
$fh2 = fopen($myFile2, 'r');
$theData = fread($fh2, filesize($myFile2));
 
$wordChunks = strtolower($wordChunks);
$wordChunks = str_replace('"', '', "$wordChunks");
$wordChunks = explode("\r\n", $data);
$ccount = count($wordChunks);
 
$Chunks = strtolower($Chunks);
$Chunks = str_replace('"', '', "$Chunks");
$Chunks = explode("\r\n", $data);
$Ccount = count($Chunks);
 
for($i = 0; $i < $Ccount; $i++){
list($page,$item_number_1,$size,$info,$pricing,$pine,$poplar) = split('[,]', $Chunks[$i]);
 
if($poplar == 'y'){
for($s = 0; $s < $ccount; $s++){
list($n, $p) = split('[,]', $wordChunks[$s]);
if($n == $item_number_1."p"){$poplar = $p;}
}
}
 
mysql_query("INSERT INTO database (page,item_number_1,size,info,pricing,pine,poplar) VALUES('$page','$item_number_1',
'$size','$info','$pricing','$pine','$poplar')") or die('Error, query failed: '.mysql_error());
}
 
fclose($fh);
fclose($fh2);
...thank you for your help...darwin

Re: For loop problems...

Posted: Sat Feb 20, 2010 2:27 am
by manohoo
I got lost on line 6, $wordChunks does not seem to be defined.
Same thing on line 11 with $Chunks... then I stopped reading the code.