On 15 Mar 2002, Jim wrote: > ** Should look like this > GALLERY 1 > Item Name Item Desc > GALLERY 2 > Item Name Item Desc > Item Name Item Desc > GALLERY 3 > Item Name Item Desc > > I have 2 tables: tblGalleries and tblItems. tblItems has a column > (itmGalley_ID) that corresponds to the gallery it belongs to in > tblGalleries (galID). I've got my SQL set right (I've tested with mysql > command line). But I can't get it to display the Gallery (galName), > every item within that gallery, and the next Gallery name going down > with its items and so on. > > I've tweaked the while statement, tried foreach loops, reorganizng that > arrys but to no avail. > > Bit of my code: > > <?php > while ($row = mysql_fetch_assoc($result)) { > ?> > <TR> > <TD> > <H1><?php echo"{$row['galName']}" ?></H1> > </TD> > <TD></TD> > <TD></TD> > </TR> > <TR> > <TD width="100"><U>Item Name</U></TD> > <TD width="200"><U>Item Desc</U></TD> > </TR> > <TR> > <TD width="100"><?php echo"{$row['itmItem_Name']}"?></TD> > <TD width="200"><?php echo"{$row['itmItem_Desc']}"?></TD> > <TD></TD> > </TR> > <?php > } > ?>
Think carefully about what you're trying to do. <? $last_galname = ''; while ($row = mysql_fetch_assoc($result)) { if ($row['galname'] != $last_galname') print "<tr><td colspan=\"2\"><h1>{$row['galname']}</h1></td></tr>\n"; $last_galname = $row['galname']; print "<tr><td width=\"100\">{$row['itmItem_Name']}</td> <td width=\"200\">{$row['itmItem_Desc']}</td></tr>\n"; } ?> Just keep track of the header, and only display it when it changes from the previous iteration. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php