Jump to content

Creating tables from database (nested if's)...


Jim R

Recommended Posts

Here is the sample page:

http://hoosierhoopsreport.com/pg-test/

 

Trying to create a table that has three sections (groupings).  That part I have figured out.  The first grouping is sorted numerically.  The second group is sorted alphabetically based on what part of the state they live in.  It's breaking down this second part that I can't seem to get.  (The third group is just what's left over, sorted alphabetically.)

 

So it needs to look like this:  (Each group and region have their own header row.  Only Group 2 is broken down into Regions.)

 

Group 1

Group 2

-Region 1

-Region 2

-Region 3

-Region 4

-Region 5

Group 3

 

The sample page above, in Group 2, it just shows Region 1 header. 

 

$query = 'SELECT * FROM a_playerRank WHERE year="2015" and position="1" ORDER BY grouping DESC,rankPos,region,nameLast';
$results = mysql_query($query) or trigger_error('MySQL error: ' . mysql_error());

$currentGrouping = false; 
$currentRegion = false;

while($line = mysql_fetch_assoc($results)) {

    if($currentGrouping != $line['grouping'])
        {
            //Status has changed, display status header

            $currentGrouping = $line['grouping'];

		if($line['grouping']==2)  {

				echo '<thead>
				<tr>
				<th class="num">#</th>
				<th class="top">Top 10</th>
				<th class="height">HT</th>';

				if (current_user_can("access_s2member_level4")){
				echo '<th class="level">Level</th>';
				}
				echo'
				<th class="school">City (School)</th>';

				if (current_user_can("access_s2member_level4")){
				echo '<th class="summer">Summer Team</th>';
				}
				echo'
				<th class="college">College</th>
				</tr>
				</thead>';
			}

		if($line['grouping']==1) {echo '<tr><th colspan="7">Best of the Rest</th></tr>';


			if($currentRegion != $line['region'])
				{
					$currentRegion = $line['region'];

				echo '<tr><th colspan="7">Region' .$line['region'] . '</th></tr>';}			


		}

		if($line['grouping']==0) echo '<tr><th colspan="7">Names to Know</th></tr>';

	}

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.