Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:45:47+00:00 2026-06-08T09:45:47+00:00

Assume I have the following result set from a mysql DB call (basic example,

  • 0

Assume I have the following result set from a mysql DB call (basic example, main will have much more data):

customerID   |   name     |     item     |     price
====================================================
11111        |   John     |    pizza     |   10.00
11111        |   John     |    burger    |   5.00
11111        |   John     |    drink     |   2.00
22222        |   Mike     |    lasagna   |   11.00
22222        |   Mike     |    drink     |   2.00
33333        |   Sam      |    burger    |   5.00
33333        |   Sam      |    fries     |   3.00
33333        |   Sam      |    shake     |   5.00
33333        |   Sam      |    drink     |   2.00

I want to display the results in a tabular form but limit the times customerID and name appear, as well as show a subtotal by each customer:

customerID   |    name    |   item    |    price
===================================================
11111        |    John    |  pizza    |   10.00
             |            |  burger   |   5.00
             |            |  drink    |   2.00
             |            |           |   **17.00**
             |            |           |
22222        |    Mike    |  lasagna  |   11.00
             |            |  drink    |   2.00
             |            |           |   **13.00**
             |            |           |
33333        |    Sam     |  burger   |   5.00
             |            |  fries    |   3.00
             |            |  shake    |   5.00
             |            |  drink    |   2.00
             |            |           |   **15.00**

I know I could make multiple DB calls but this is wasteful when it can be done in one. I am having problems cycling through my result set in table 1 and properly formatting with PHP using as shown in table 2. Is it possible the way I have it shown or do I have to make multiple DB calls to do so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:45:49+00:00Added an answer on June 8, 2026 at 9:45 am

    This is better solved directly in PHP, because you will be free to modify the output as you wish.

    So basically you will do something like (untested):

    $res = mysql_query("SELECT costumerID, name, item, price
                        FROM orders 
                        ORDER BY customerID, item");
    
    echo "<table id='orders'>".
          "<tr><th>Name</th>".
          "<th>Item</th>".
          "<th>Price</th></tr>";
    
    $lastCostumer = -1;
    $subTotal = 0; 
    while ($row = mysql_fetch_array($res))
         {
         // New costumer
         if ($lastCostumer != $row['costumerID'])
               {
               // Write the subtotal of previous costumer, unless this is the 1st one
               if ($lastCostumer != -1)
                  echo "<tr><td></td>".
                       "<td></td>".
                       "<td><b>**".$subTotal."**</b></td></tr>";
    
               $subTotal = 0; 
               echo "<tr><td>".$row['name']."</td>".
                    "<td>".$row['item']."</td>".
                    "<td>".$row['price']."</td></tr>";
    
               $subTotal = $subTotal + $row['price'];
               $lastCostumer = $row['costumerID'];
               }
         else // Same costumer
               {
               echo "<tr><td></td>".  // Don't write the name
                    "<td>".$row['item']."</td>".
                    "<td>".$row['price']."</td></tr>";
    
               $subTotal = $subTotal + $row['price'];
               }
         }
    
    // Write the subtotal of last costumer
    echo "<tr><td></td>".
         "<td></td>".
         "<td><b>**".$subTotal."**</b></td></tr>";
    
    echo "</table>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have the following query against the AdventureWorks DB: var result = from
My database is in MySQL. Assume I have the following table: id number 1
I know for more than one result, you don't have much choice for using
Assume I have the following ; def test(): while 1: a = b time.sleep(60)
Assume I have the following arrays: N = 8 M = 4 a =
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume I have the following input in Pig: some And I would like to
Assume I have the following style table, col1 col2 and col3 have same value
Assume I have the following classes class Genre { static hasMany=[author:Author] } class Author{
Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.