kaykay
02-01-2010, 12:00 PM
Hi - first time poster here.
I've been stuck on a problem for about two days and I can't figure out the solution.
I'm using FPDF, but my problem is mainly PHP/MySQL based.
I've got some code that has a nested FOREACH and WHILE loops in it. Now the code seems to running almost perfectly, except that the result of the WHILE loop doesn't clear once it has been run through twice. So essentially the result of the WHILE loop is the current result + previous result
$y=$inv_group_array_grab_unique; //grabs a unique array (normally something like "1,2,5,22,65")
foreach ($y as $inv_group_id)
{
//Inventory Fetching Code
$inventory_fetch_sql = "SELECT * FROM inventory WHERE supplier = '$supplier_id' AND inv_group = '$inv_group_id' "; //grabs the data that I want to display
$inventory_fetch = mysql_query($inventory_fetch_sql,$con);
//Next step
while($row2 = mysql_fetch_array($inventory_fetch))
{
$ingredient_get = $row2["inv"];
$column_inventory_item = $column_inventory_item.$ingredient_get."\n";
}
$pdf->SetFont('Arial','',8);
$pdf->Multicell(100,4,"Group name to go here",1);
$pdf->SetFont('Arial','',8);
$pdf->MultiCell(125,4,$column_inventory_item,1);
//GROUP LOOP ENDS HERE
}
the result comes out like this:
Group 1:
***Loop 1's results***
Group 2:
***Loop 1's results***
***Loop 2's results***
Group 3:
***Loop 1's results***
***Loop 2's results***
***Loop 3's results***
when it should look like:
Group 1:
***Loop 1's results***
Group 2:
***Loop 2's results***
Group 3:
***Loop 3's results***
i'm lost...
does anyone here have any ideas?
Thanks
I've been stuck on a problem for about two days and I can't figure out the solution.
I'm using FPDF, but my problem is mainly PHP/MySQL based.
I've got some code that has a nested FOREACH and WHILE loops in it. Now the code seems to running almost perfectly, except that the result of the WHILE loop doesn't clear once it has been run through twice. So essentially the result of the WHILE loop is the current result + previous result
$y=$inv_group_array_grab_unique; //grabs a unique array (normally something like "1,2,5,22,65")
foreach ($y as $inv_group_id)
{
//Inventory Fetching Code
$inventory_fetch_sql = "SELECT * FROM inventory WHERE supplier = '$supplier_id' AND inv_group = '$inv_group_id' "; //grabs the data that I want to display
$inventory_fetch = mysql_query($inventory_fetch_sql,$con);
//Next step
while($row2 = mysql_fetch_array($inventory_fetch))
{
$ingredient_get = $row2["inv"];
$column_inventory_item = $column_inventory_item.$ingredient_get."\n";
}
$pdf->SetFont('Arial','',8);
$pdf->Multicell(100,4,"Group name to go here",1);
$pdf->SetFont('Arial','',8);
$pdf->MultiCell(125,4,$column_inventory_item,1);
//GROUP LOOP ENDS HERE
}
the result comes out like this:
Group 1:
***Loop 1's results***
Group 2:
***Loop 1's results***
***Loop 2's results***
Group 3:
***Loop 1's results***
***Loop 2's results***
***Loop 3's results***
when it should look like:
Group 1:
***Loop 1's results***
Group 2:
***Loop 2's results***
Group 3:
***Loop 3's results***
i'm lost...
does anyone here have any ideas?
Thanks