maliary Posted April 13, 2007 Share Posted April 13, 2007 Hi, I have a table in mysql with 2 columns.group name and the group parameters. There is one group name with several group parameters. I would like to retrieve this from the database such that it will only display one group and the other several parameters in it,for all the diffrent groups. does anyone know how i can go about this? Maliary Link to comment https://forums.phpfreaks.com/topic/46898-php-display-solution-required/ Share on other sites More sharing options...
craygo Posted April 13, 2007 Share Posted April 13, 2007 of course <?php echo "<table width=250 align=center cellspacing=0 cellpadding=0>\n"; // Set initial group values $lastgroup = ''; // Query database $sql = "SELECT * FROM table ORDER BY name ASC "; $res = mysql_query($sql) or die(mysql_error()); while ($rows = mysql_fetch_assoc($res)){ // Print Group header if ($rows['name'] != $lastgroup) { // Print Group Name echo "<tr> <td colspan=2 align=left><strong>Group: ".$rows['name']."</strong></td> </tr>\n"; } // Print Database Details echo "<tr> <td width=50> </td> <td width=200 align=center>".$rows['parameters']."</td> </tr>\n"; // Reset group values $lastgroup = $rows['name']; } echo "</table>\n"; ?> Ray Link to comment https://forums.phpfreaks.com/topic/46898-php-display-solution-required/#findComment-228637 Share on other sites More sharing options...
maliary Posted April 14, 2007 Author Share Posted April 14, 2007 Thanks to your solution. However i would like to display one group name and all the other parameters in it.Instead of repeating the group name several times for each parameter. Maliary. Link to comment https://forums.phpfreaks.com/topic/46898-php-display-solution-required/#findComment-229081 Share on other sites More sharing options...
Barand Posted April 15, 2007 Share Posted April 15, 2007 If you ran the above code, as I did on on of my tables, you'd see output like this. [pre]Group: C Piccadilly Piccadilly Group: E Ashton Oldham Hyde Ashton Oldham Group: N Middleton Rochdale Bolton Rochdale Bury Group: S Stockport Altrincham Wythenshawe Group: W Leigh Wigan Wigan [/pre] So a ) why bother posting if you don't accept the solution b ) I closed your second post on this same question before you waste anyone else's time (read the forum rules regarding double posting) Link to comment https://forums.phpfreaks.com/topic/46898-php-display-solution-required/#findComment-229608 Share on other sites More sharing options...
maliary Posted April 15, 2007 Author Share Posted April 15, 2007 Hi, Thanks a lot for the solution. I had tried it previously and it failed however i made some changes and it now works alright. Sorry for the double post. Maliary Link to comment https://forums.phpfreaks.com/topic/46898-php-display-solution-required/#findComment-229648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.