Group results by field data ... - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-07-2011, 11:32 PM   #1 (permalink)
Regular User
 
Join Date: Nov 2008
Posts: 20
Default Group results by field data ...

Code:
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.
pepe_lepew1962 is offline   Reply With Quote
Sponsored Links
Old 01-12-2011, 05:01 AM   #2 (permalink)
Junior Member
 
Join Date: Jan 2011
Posts: 18
Default Re: Group results by field data ...

Did you tried GROUP BY ?
after_me is offline   Reply With Quote
Old 01-23-2011, 11:59 PM   #3 (permalink)
Junior Member
 
jalicia18's Avatar
 
Join Date: Nov 2010
Location: Philippines
Posts: 14
Send a message via Skype™ to jalicia18
Default Re: Group results by field data ...

Is this what you're looking for?

Quote:
$sql = "Select a.fldField1, a.fldField2, a.fldField3 FROM tblTable1 a GROUP BY a.fldField1";
$query = mysql_query($sql);
while($result = mysql_fetch_array($query))
{
echo "Field1 Name 1: " . $result['fldField1'] . "<br/>";
echo "Field1 Name 2: " . $result['fldField2'] . "<br/>";
echo "Field1 Name 3: " . $result['fldField3'] . "<br/>";
echo "<br/>";
}
jalicia18 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:29 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting