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 8964713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:39:03+00:00 2026-06-15T16:39:03+00:00

Normally when I group stuff together it is for the obvious use to group

  • 0

Normally when I group stuff together it is for the obvious use to group together duplicates, but I am making a winners page that shows winners for a bunch of jackpots, some jackpots have 1 winner while other have 3, using GROUP BY date will work if there is only 1 winner but will only show 1 winner when there should be 3.

Here is my code

$result = $db->query("SELECT * FROM r_winners GROUP BY date ORDER BY date DESC");
while($rows = $result->fetch_assoc()){
print"<table class='cashout' style='width:100%;'>
<th colspan='3'>".$rows['jackpot_name']." Winners</th>
<tr>
<td style='width:33%;'>".$rows['winner']."</td><td style='width:33%;'>$".$rows['amount']."</td><td style='width:33%;'>".date("m/d/Y", $rows['date'])."</td></tr>
</tr></table>";
}

It prints out a table like such

---------------------------------------
Daily     Jackpot     Winners
Username|  $5.00   |  12/5/2012         // This table is right, because there is only 1 winner
---------------------------------------

Because there is only 1 winner then GROUP BY really has no affect here

Here is a table for multiple winners

---------------------------------------
Monthly     Jackpot     Winners
Username  |  $5.00   |  12/5/2012         // This table is wrong, because there should be 3 winners
---------------------------------------

It needs to look like this

---------------------------------------
Monthly     Jackpot     Winners
Username  |  $5.00   |  12/5/2012 
Username2 |  $2.00   |  12/5/2012
Username3 |  $1.00   |  12/5/2012        
---------------------------------------

How can I accomplish this?

EDIT: This can maybe explain this better https://gist.github.com/4221167

  • 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-15T16:39:04+00:00Added an answer on June 15, 2026 at 4:39 pm

    Change your query to just use ORDER BY and reformat your loop, placing the table elements outside, and only printing the header once

    $result = $db->query("SELECT * FROM r_winners ORDER BY date DESC");
    print"<table class='cashout' style='width:100%;'>";
    $jackpot_name = '';
    while($rows = $result->fetch_assoc()){
        if ($jackpot_name != $rows['jackpot_name']) {
            $jackpot_name = $rows['jackpot_name'];
            print "<th colspan='3'>".$rows['jackpot_name']." Winners</th>";
        }
        print "<tr><td style='width:33%;'>".$rows['winner']."</td><td style='width:33%;'>$".$rows['amount']."</td><td style='width:33%;'>".date("m/d/Y", $rows['date'])."</td></tr>";
    }
    print "</table>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that you have a normally distributed variable y with a 3-group categorical
I'll preface this by saying that I usually work in C#/.Net. Normally, I use
As a dev I normally group my explorer detail view by file type. This
Normally, if I want to start a new activity I can use StartActivity(typeof(foo)); This
Normally we use window.location.href=/index.php?querystring; in javascript. Is there a way to send the querystring
Normally HTML check boxes are grouped based on name. Is it possible to group
Our group is somewhat new to JVM based development. We are developing applications that
I normally use this step to set up records with factory_girl: Given /^the following
Can I use a Celery Group primitive as the umbrella task in a map/reduce
I have a list that I would like to group and edit within a

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.