emexinc Posted February 19, 2010 Share Posted February 19, 2010 ...i am trying to import a .txt file into a mysql database and at the same time if a condition is met, then have some information changed with information from a second .txt file... ...here is my coding thus far... $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); $Chunks = strtolower($Chunks); $Chunks = str_replace('"', '', "$Chunks"); $Chunks = explode("\r\n", $data); for($i = 0; $i < count($Chunks); $i++){ list($page,$item_number_1,$size,$info,$pricing,$pine,$poplar) = split('[,]', $Chunks[$i]); if($poplar == 'y'){ for($s = 0; $s < count($wordChunks); $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); ...thanks for the help...darwin Link to comment https://forums.phpfreaks.com/topic/192652-for-loop-is-not-working/ Share on other sites More sharing options...
SchweppesAle Posted February 19, 2010 Share Posted February 19, 2010 I wouldn't place count($wordChunks) within the for construct, it will call the count() function during each iteration. what does the following statement return? $size = count($wordChunks); echo var_dump($size); Link to comment https://forums.phpfreaks.com/topic/192652-for-loop-is-not-working/#findComment-1014967 Share on other sites More sharing options...
emexinc Posted February 19, 2010 Author Share Posted February 19, 2010 ...the above statement returns int(1583) Link to comment https://forums.phpfreaks.com/topic/192652-for-loop-is-not-working/#findComment-1014975 Share on other sites More sharing options...
SchweppesAle Posted February 19, 2010 Share Posted February 19, 2010 echo var_dump($poplar) from within the for statement then. Was that suppose to be $popular? if($popular == 'y') actually, you'll want to run the same check on the next conditional statement as well. Just go through each one and you'll find it. Link to comment https://forums.phpfreaks.com/topic/192652-for-loop-is-not-working/#findComment-1014979 Share on other sites More sharing options...
emexinc Posted February 19, 2010 Author Share Posted February 19, 2010 ...actually poplar is the correct spelling for a species of wood... Link to comment https://forums.phpfreaks.com/topic/192652-for-loop-is-not-working/#findComment-1014981 Share on other sites More sharing options...
emexinc Posted February 19, 2010 Author Share Posted February 19, 2010 ...the code seems to have an issue with this line... if($n == $item_number_1."p"){$poplar = $p;} ...if that line is taken out then everything runs fine, but information from the second file is not compared to information from the first file... Link to comment https://forums.phpfreaks.com/topic/192652-for-loop-is-not-working/#findComment-1014989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.