-1

The issue im having is when running a while loop inside of a while loop in php the html content after the second while loop is not being rendered

for a live demonstration http://naturalflame.altervista.org/home.php

I originally didnt use a continue after the second loop but then none of the other rows populate because it just stops after the second loop after adding the continue after the second loop the other rows populate but the description and action field are left out

<div id="main">
        <h1>Product List</h1> 
        <table> 
            <tr> 
                <th>Size</th>  
                <th>Price</th> 
                <th>Flavor Selection</th>
                <th>Flavor Description</th>
                <th>Blend Selection</th>
                <th>Action</th> 
            </tr> 
            <?
                $sql="SELECT * FROM products ORDER BY price ASC"; 
                $query=mysql_query($sql) or die(mysql_error());

                while($row = mysql_fetch_object($query)){
                    $id = $row->id;
                    $size = $row->size;
                    $price = $row->price;
                ?>
                <tr> 
                    <td><? echo $size; ?></td> 
                    <td>$<? echo $price; ?></td> 
                    <td>
                        <select onchange="ChangeDescription(<? echo $id; ?>)" id="dSelection<? echo $id; ?>">
                        <option value="Select a flavor">Select a flavor</option>
                        <?
                            $sql2 = "SELECT * FROM flavors ORDER BY id ASC";
                            $query2 = mysql_query($sql2) or die(mysql_error());

                            while($row2 = mysql_fetch_object($query2)){
                                $name = $row2->name;
                                echo "
                                <option value='$name'>$name</option>
                                ";
                            }
                        ?>
                        </select>
                    </td>
                    <td id="description<? echo $id; ?>">Flavor Description</td>
                    <td><a href="home.php?page=products&action=add&id=<?php echo $row['id'] ?>&flavor=">Add to cart</a></td>
                </tr>
            <?}?>
        </table>
        </div><!--end main-->
FlamingGenius
  • 216
  • 2
  • 21

1 Answers1

2

You seem to be using an object as an array causing an error on your page.

This code: $row['id'] is probably just supposed to be $id

If you hadn't of already put it in a placeholder it would be $row->id

Adam Forbis
  • 463
  • 3
  • 11