php - display menu grouped by headings - array grouped by -
i looked around grouped didn't find either made sense or worked.
im trying make menu grouped headings salads/pizza/pasta etc got save database fine , have reading array( think called multidimensional[if know dumped array called please tell me id know].
here array dump
array ( [heading] => array ( [0] => salads [1] => salads [2] => pasta ) [special] => array ( [0] => [1] => [2] => ) [item] => array ( [0] => small green [1] => regular caesar [2] => baked lasagna ) [description] => array ( [0] => grape tomatoes, onions, green peppers , cucumbers on bed of crisp lettuce. [1] => classic recipe romaine lettuce , croutons [2] => meat sauce, tomato vegetarian sauce or alfredo sauce ) [price] => array ( [0] => see desc [1] => $5.99 [2] => $9.69 ) [notes] => array ( [0] => available in small ($2.99), regular ($5.99) [1] => [2] => ) [submit_val] => submit )
im using php output data(minus mysql info)
for($i = 0; $i < count($array['heading']); $i++) { ?> <tr> <td colspan="2" align="center" class="section"><?=$array['heading'][$i]; ?></td></tr> <tr> <td colspan="2"> </td></tr> <tr> <td class="selection"><b><?=$array['item'][$i]; ?>. </b> <i><?=$array['description'][$i]; ?></i><br> <small><i><?=$array['special'][$i]; ?></i></small><small><?=$array['notes'][$i]; ?></small> </td> <td class="selection" align="right" valign="top"><?=$array['price'][$i]; ?></td> </tr> <? }// loop
here menu looks screenshot of menu
so how 1 make salads in 1 heading , not 2 please, mind have multiple items in multiple headings(with same headings ie various pizzas etc)
thank in advance may provide
you can cache last heading , if statement:
<?php $last_heading = ''; for($i = 0; $i < count($array['heading']); $i++) { if ($last_heading !== $array['heading'][$i]) { ?> <tr> <td colspan="2" align="center" class="section"><?=$array['heading'][$i]; ?></td></tr> <?php $last_heading = $array['heading'][$i]; } // end if ?> <tr> <td colspan="2"> </td></tr> <tr> <td class="selection"><b><?=$array['item'][$i]; ?>. </b> <i><?=$array['description'][$i]; ?></i><br> <small><i><?=$array['special'][$i]; ?></i></small><small><?=$array['notes'][$i]; ?></small> </td> <td class="selection" align="right" valign="top"><?=$array['price'][$i]; ?></td> </tr> <? }// loop
this assume headings in order that.
Comments
Post a Comment