Flic
07-20-2007, 03:07 AM
Hi,
I've got a while loop in a while loop and it looks fine to me but its coming up with a parse error:
Parse error: syntax error, unexpected '}' in ... on line 55
With the following code:
<?php
$sql = 'SELECT * FROM item;';
$result = $db->query($sql);
while ($row = $result->fetch()) {
$sizes = explode(';',$row["packet_size"]); // Split the different packet sizes up
$prices = explode(';',$row["packet_price"]); // Split the different packet prices up
$packets = count($sizes); // Count the number of different packet sizes
$output2[] = '<h1>'.$row["item_name"].'</h1>';
$output2[] = '<img src="images/'.$row["picture"].'" alt="'.$row["item_name"].'">';
$output2[] = '<br>'.$row["description"].'<br>';
$i=0;
while ($i < $packets){
$output2[] = $sizes[i].'<br>';
$output2[] = $prices[i].'<br><br>';
$i++
} <--
}
echo join('',$output2);
?>
The } in question is the one closing the second while loop. This needs to be here so not sure why its complaining!
I tried a do while loop as well but the same thing happens and a for loop doesn't complain but the section that should be printed out isn't.
Any pointers much appreciated!
Thanks, Flic
I've got a while loop in a while loop and it looks fine to me but its coming up with a parse error:
Parse error: syntax error, unexpected '}' in ... on line 55
With the following code:
<?php
$sql = 'SELECT * FROM item;';
$result = $db->query($sql);
while ($row = $result->fetch()) {
$sizes = explode(';',$row["packet_size"]); // Split the different packet sizes up
$prices = explode(';',$row["packet_price"]); // Split the different packet prices up
$packets = count($sizes); // Count the number of different packet sizes
$output2[] = '<h1>'.$row["item_name"].'</h1>';
$output2[] = '<img src="images/'.$row["picture"].'" alt="'.$row["item_name"].'">';
$output2[] = '<br>'.$row["description"].'<br>';
$i=0;
while ($i < $packets){
$output2[] = $sizes[i].'<br>';
$output2[] = $prices[i].'<br><br>';
$i++
} <--
}
echo join('',$output2);
?>
The } in question is the one closing the second while loop. This needs to be here so not sure why its complaining!
I tried a do while loop as well but the same thing happens and a for loop doesn't complain but the section that should be printed out isn't.
Any pointers much appreciated!
Thanks, Flic