Jump to content

Table Display grouped by specific field


kemper

Recommended Posts

I operate a youth sports website and i display my current alignments in a long running list of teams (one field within my table) with association divisions (another field within table).

 

I would like to group them by divisions, like a two column table for better clarification.

 

Example:

Division 1

Division 2

Team 1[br]Team 2[br]Team 3[br]Team 4[br]Team 5

Team 1[br]Team 2[br]Team 3[br]Team 4

[br][br]

Division 3

Division 4

Team 1[br]Team 2[br]Team 3[br]Team 4

Team 1[br]Team 2[br]Team 3[br]Team 4[br]Team 5

[br][br]

 

How do I modify my code???

 

$sql = dbquery(
"SELECT ter.*, user_id,user_name FROM s2008_registrations ter
LEFT JOIN ".$db_prefix."users tusr ON ter.reg_user=tusr.user_id
ORDER BY s08div ASC, team ASC"
);
if (dbrows($sql)) {
$i = 0;
echo "<table width='100%' cellpadding='0' cellspacing='1' class='tbl-border'>
<tr>
<td class='tbl2' width='25%'>Division</td>
<td class='tbl2' width='45%'>Team Name</td>
</tr>\n";
while ($data = dbarray($sql)) {
	$i % 2 == 0 ? $tclass="tbl1" : $tclass="tbl2";
	echo "<tr>
<td class='$tclass' width='25%'><font size='1'>".$data['s08div']."</font></td>
<td class='$tclass' width='45%'>
<a href='".FUSION_SELF."?step=view&id=".$data['id']."'><font size='1'>".$data['team']."</font></a></td>

</tr>\n";
}
echo "</table>

Link to comment
https://forums.phpfreaks.com/topic/74389-table-display-grouped-by-specific-field/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.