I have a mysql table
|------------|-----------|------------|
| Catagory | Item | Price |
|------------|-----------|------------|
| Soup | Split Pea | $1.99 |
| Soup | Onion | $2.99 |
| MainCourse | Steak | $9.99 |
| MainCourse | Shrimp | $11.99 |
|-------------------------------------|
I am looking to end up with html unordered list
Soup<br>
<ul>
<li class="menuItem">Split Pea - $1.99</li>
<li class="menuItem">Onion - $2.99</li>
</ul>
MainCourse<br>
<ul>
<li class="menuItem">Steak - $9.99</li>
<li class="menuItem">Shrimp -$11.99</li>
</ul>
This is my php
<?php $testvalue='1' ?>
<?php do { ?>
<?php if ($testvalue!=$row_rs_items['category']) { echo $row_rs_items['category']; echo "<br>","<ul>"; } ?>
<li class="menuItem"><?php echo $row_rs_items['name']; ?> - <?php echo $row_rs_items['price']; ?></li>
<?php $testvalue=$row_rs_items['category']; ?>
<?php } while ($row_rs_items = mysql_fetch_assoc($rs_items)); ?>
The code works to create opening <UL> on the first entry for catagory. However I am looking for a way to add a </UL> when the next row is of a new catagory. Is there a way to peak in to the next row when interating over the recordset?
Try this,