Log in

View Full Version : Group results by field data ...



pepe_lepew1962
01-08-2011, 04:31 AM
Hello, I am having problems with grouping records while showing the group data only once. I am trying to get them in a html table that would look like:

+------------------------+----------------------+------------------------+
| tblTable1.fldField1 | tblTable1.fldField2 | tblTable1.fldField3 |
+------------------------+----------------------+------------------------+
| 12653 | PBXL | 396.52 |
| | ABCD | 426.28 |
| | GEDL | 385.20 |
+------------------------+----------------------+------------------------+
| 12654 | ABCD | 515.18 |
| | FGHL | 520.00 |
+------------------------+----------------------+------------------------+
| 12659 | PBXL | 612.35 |
| | FGHL | 619.20 |
| | XTRL | 420.39 |
+------------------------+----------------------+------------------------+


<?php
//
require("connect.php");
//
$mydata101 = "SELECT tblTable1.fldField1 as 'group', tblTable1.fldField2, tblTable1.fldField3 as 'name' FROM tblTable1 GROUP BY tblTable1.fldField1";
$mydata102 = mysql_query($mydata101);
//
//
$group = null;
while($row = mysql_fetch_array($mydata102))
{
if($row['group'] != $group)
{
echo $row['group'];
$group = $row['group'];
//
$row['name'];
//
}
//
}
?>


Any help would be great appreciated.