For loop problems...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
emexinc
Forum Newbie
Posts: 1
Joined: Fri Feb 19, 2010 2:52 pm

For loop problems...

Post 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
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: For loop problems...

Post 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.
Post Reply