kemper Posted December 9, 2007 Share Posted December 9, 2007 If my table has a structure like: Division Team A Team 1 A Team 2 A Team 8 A Team 9 B Team 3 B Team 4 B Team 6 B Team 7 How can I change my script of: <table width='100%' cellpadding='0' cellspacing='1' class='tbl-border'> <tr> <td class='tbl2'><b>Division</b></td> <td class='tbl2'><b>Team</b></td> </tr>\n"; while ($data = dbarray($sql)) { $i % 2 == 0 ? $tclass="tbl1" : $tclass="tbl2"; echo "<tr> <td class='$tclass'><font size='1'>".$data['f07div']."</font></td> <td class='$tclass'> <font size='1'>".$data['Team']."</font></td> </tr>\n"; } echo "</table> To display some type of break between each division? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 9, 2007 Share Posted December 9, 2007 You check to see if $data['f07div'] is different from the previous value. If it is, output a break. Quote Link to comment Share on other sites More sharing options...
kemper Posted December 9, 2007 Author Share Posted December 9, 2007 how do I do that? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 9, 2007 Share Posted December 9, 2007 <?php echo "<table width='100%' cellpadding='0' cellspacing='1' class='tbl-border'> <tr> <td class='tbl2'><b>Division</b></td> <td class='tbl2'><b>Team</b></td> </tr>\n"; $prev = ''; while ($data = dbarray($sql)) { $tclass = $i % 2 == 0 ? "tbl1" : "tbl2"; if ($data['f07div'] != $prev) { // if division changed echo "<tr><td colspan='2'> </td></tr>\n"; // blank row $prev = $data['f07div']; } echo "<tr> <td class='$tclass'><font size='1'>".$data['f07div']."</font></td> <td class='$tclass'> <font size='1'>".$data['Team']."</font></td> </tr>\n"; } echo "</table>\n" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.