Group results by field data ...

Discussion in 'PHP' started by pepe_lepew1962, Jan 7, 2011.

  1. #1
    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.
    Code (markup):

     
    pepe_lepew1962, Jan 7, 2011 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Whats your MYSQL table structure ?
     
    tvoodoo, Jan 7, 2011 IP