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
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";
?>

Link to comment
Share on other sites

...i've tried your fix and that didn't change anything...do you have any other ideas? How can the page be displayed even though it's obviously running into an error and not displaying a simple echo statement at the end?...thanks again for your help...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.