[SOLVED] Ordering results into groups

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

[SOLVED] Ordering results into groups

Post by Linkjames »

I have a database with tests grouped into Suites, groups, then tests. I would like to be able to output them in the following format onto a web page

Code: Select all

| Suite 1 | Group 1 | test 1 |
--------------------------------
                    | test 2 |
                    | test 3 |
                    | test 4 |
                    | test 5 |
--------------------------------
| Suite 1 | Group 2 | test 1 |
--------------------------------
                    | test 2 |
                    | test 3 |
                    | test 4 |
                    | test 5 |
--------------------------------
| Suite 2 | Group 1 | test 1 |
--------------------------------
                    | test 2 |
                    | test 3 |
                    | test 4 |
                    | test 5 |
--------------------------------
and so on.
I have tryed the following

Code: Select all

$selsuite = mysql_query("SELECT 'suite' FROM `tests`");
		while ($resarraysuite = mysql_fetch_array($selsuite))
	{
		
		$selgroup = mysql_query("SELECT group FROM `tests'");
		while ($resarraygroup = mysql_fetch_array($selgroup))
		{
			$seltest = mysql_query("SELECT test FROM `tests` ORDER BY 'suite'");
			while ($resarraytest = mysql_fetch_array($seltest))
			{	
			$suite = $resarraysuite['suite'];
		echo $suite;	
			
		$group = $resarraygroup['group'];	
		echo $group;	
			
		$test = $resarraytest['test'];
		echo $test;
		Echo "<br>";
		
	}
}
}
but with no luck.

I am not looking for someone to give me the code, just to give me an idea of how to start (as the above only ouputs the suites)

Cheers in advance - LinkJames
Last edited by Linkjames on Mon Jun 28, 2004 11:12 am, edited 1 time in total.
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Forgot to mention, there can be any number of tests in a group, and any number of groups in a suite
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Had a re-think and figured it out.

Code: Select all

$sel = mysql_query("SELECT * FROM `tests` ORDER BY 'suite'");
		echo "<table>";
	while ($resarray = mysql_fetch_array($sel))
		
	{
		
		$suite = $resarray['suite'];
		$group = $resarray['group'];
		$test = $resarray['test'];
		if ($suitetemp	== $suite)
		{
			if ($grouptemp	== $group)
			{
			echo "<tr><td></td><td></td><td>";
			echo $test;
			echo "</td></tr>";
			$suitetemp = $suite;
			$grouptemp = $group;
			}
			else
			{
			echo "<tr><td></td><td>";
			echo $group;
			echo "</td><td>";
			echo $test;
			echo "</td></tr>";
			$suitetemp = $suite;
			$grouptemp = $group;
		}
		}
		else
		{
			
		if ($grouptemp	== $group)
		{
			echo "<tr><td>";
			echo $suite;
			echo "</td><td></td><td>";
			echo $test;
			echo "</td></tr>";
			$suitetemp = $suite;
			$grouptemp = $group;
			}
			else
			{
			echo "<tr><td>";
			echo $suite;
			echo "</td><td>";
			echo $group;
			echo "</td><td>";
			echo $test;
			echo "</td></tr>";
			$suitetemp = $suite;
			$grouptemp = $group;
		}
		}
	}
		echo "</table>";
Post Reply