Jump to content

For Loop in a For Loop


emexinc

Recommended Posts

I have placed a FOR LOOP in a FOR LOOP, I am not getting any error messages, but my echo statement at the end is not being displayed, as well as the fact that the data for the most part is being inserted, but when the first file is checked against the second something is not working, because under the poplar column i still have 'y' where it should of switched it with a price...thanks for the help...darwin

 

 

$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,$red_oak,$white_oak,$alder,$fir,$hemlock,$maple,$cherry,$hickory,$mahogany,$lyptus,$brazillian_cherry,$beech,$maple_with_leaf,$mdf,$birch,$walnut) = split('[,]', $Chunks[$i]);
if($poplar == 'y'){
$theData = str_replace('"', '', "$theData");
$wordChunks = explode("\r\n", $theData);
for($s = 0; $s < count($wordChunks); $s++){
list($item_number_2, $price) = split('[,]', $wordChunks[$s]);
if($item_number_1 == $item_number_2){$poplar = $price;};
};
};
mysql_query("INSERT INTO alldata (page,item_number_1,size,info,pricing,pine,poplar,red_oak,white_oak,alder,fir,hemlock,maple,cherry,hickory,mahogany,lyptus,brazillian_cherry,beech,maple_with_leaf,mdf,birch,walnut) VALUES('$page','$item_number_1','$size','$info','$pricing','$pine','$poplar','$red_oak','$white_oak','$alder','$fir','$hemlock','$maple','$cherry','$hickory','$mahogany','$lyptus','$brazillian_cherry','$beech','$maple_with_leaf','$mdf','$birch','$walnut')") or die('Error, query failed: '.mysql_error());
};
echo "Importing all information complete";

Link to comment
https://forums.phpfreaks.com/topic/190400-for-loop-in-a-for-loop/
Share on other sites

it could be because you have semi-colons after you braces try this:

 

<?php
$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,$red_oak,$white_oak,$alder,$fir,$hemlock,$maple,$cherry,$hickory,$mahogany,$lyptus,$brazillian_cherry,$beech,$maple_with_leaf,$mdf,$birch,$walnut) = split('[,]', $Chunks[$i]);
if($poplar == 'y'){
	$theData = str_replace('"', '', "$theData");
	$wordChunks = explode("\r\n", $theData);
	for($s = 0; $s < count($wordChunks); $s++){
		list($item_number_2, $price) = split('[,]', $wordChunks[$s]);
		if($item_number_1 == $item_number_2){$poplar = $price;};
	}
}
mysql_query("INSERT INTO alldata (page,item_number_1,size,info,pricing,pine,poplar,red_oak,white_oak,alder,fir,hemlock,maple,cherry,hickory,mahogany,lyptus,brazillian_cherry,beech,maple_with_leaf,mdf,birch,walnut) VALUES('$page','$item_number_1','$size','$info','$pricing','$pine','$poplar','$red_oak','$white_oak','$alder','$fir','$hemlock','$maple','$cherry','$hickory','$mahogany','$lyptus','$brazillian_cherry','$beech','$maple_with_leaf','$mdf','$birch','$walnut')") or die('Error, query failed: '.mysql_error());
}
echo "Importing all information complete";
?>

...it does not display any errors...i found another post where i link that page to a new one where it then can do an error check (i wish i could explain it better) and the only repeated item that i comes up with is "Undefined Offset: " with various numbers all from the same line of code in my file.

 

list($page,$item_number_1,$size,$info,$pricing,$pine,$poplar,$red_oak,$white_oak,$alder,$fir,$hemlock,$maple,$cherry,$hickory,$mahogany,$lyptus,$brazillian_cherry,$beech,$maple_with_leaf,$mdf,$birch,$walnut) = split('[,]', $Chunks[$i]);

 

...from splitting this line of code among different lines, it seems the last part is causing this...

 

) = split('[,]', $Chunks[$i]);

 

...i don't know where to go from here...thanks for all the help...darwin

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.