For loop Question
Posted: Wed Feb 09, 2011 3:48 pm
Hey guess I have a question about For Loops. I'm very new to php so please forgive anything stupid I am doing
The follow code shows what I am trying to do with my for loop. It works great except that the $sizu value is spread out over all the fields. So instead of saying 150 in the first record set it prints 1 and then in the second record it prints 2 etc. Any idea what is causing this? If you need to see the rest of the code let me know I'm just trying to save bandwidth at first.
Code: Select all
for ($i=0; $i < count($var); $i++)
{
$quer = ("SELECT sbbx0, sbsizu FROM dwoshp WHERE sbfile = '$_POST[order]' and sbbrnu = '$_POST[location]' AND sbvaru = '$varu[$i]'");
$res = mysql_query($quer);
while($r = mysql_fetch_array($res)) {
$quant = $r['sbbx0'];
$sizu = $r['sbsizu'];
}
$query_AddDots = "INSERT INTO tempresult(variety,grade,cont, quantity, size) VALUES ('$var[$i]', '$invgrade[$i]','TP','$quant', $sizu[$i])";
$AddDots = mysql_query($query_AddDots) or die(mysql_error());
}