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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:47:32+00:00 2026-05-22T00:47:32+00:00

Trying to get my results sorted by month and displayed in a table. Where

  • 0

Trying to get my results sorted by month and displayed in a table. Where am I going wrong?

Query:

mysql_query("SELECT COUNT(*), DATE_FORMAT(DATE(`dPostDateTime`), '%W, %b, %e') AS `day`, DATE(`dPostDateTime`) AS 'date' FROM `tblQA` WHERE cCategory IN ('Football','Baseball','Basketball','Hockey') AND dPostDateTime >= '2010-08-01' AND dPostDateTime <= '2011-07-31' GROUP BY `month`");

PHP Code:

while($row = mysql_fetch_assoc($monthlyQ))
{
$printedRecords1++;
echo "<tr class='forum'>";
echo "<td class='forum'>" . $row['month'] . "</td>";
echo "<td class='forum'>" . $row['COUNT(*)'] . "</td>";
echo "</tr>";
}
for ($i = $printedRecords1; $i < $Print; $i++) {
echo "<tr class='forum'>"; 
echo "<td class='forum'>&nbsp;</td>";
echo "<td class='forum'>&nbsp;</td>";
echo "</tr>";
}
echo "</table></td><td>";
  • 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-05-22T00:47:33+00:00Added an answer on May 22, 2026 at 12:47 am

    I assume when you say you’re trying to sort by month, you just mean you’re trying to figure out how many rows are in each month, since that looks what what your code is doing.

    If you actually have a ‘month’ field in your table, then your SQL is fine, except that you never actually select that field, so $row['month'] shouldn’t have a value with that SQL.
    So you need to select it like below:

    mysql_query("SELECT COUNT(*), `month`, DATE_FORMAT(DATE(`dPostDateTime`), '%W, %b, %e') AS `day`, DATE(`dPostDateTime`) AS 'date' FROM `tblQA` WHERE cCategory IN ('Football','Baseball','Basketball','Hockey') AND dPostDateTime >= '2010-08-01' AND dPostDateTime <= '2011-07-31' GROUP BY `month`");
    

    If you don’t have a ‘month’ field (and just have the date field, which would mean your query as given shouldn’t be working) you need to be creating that in a similar way as your ‘day’.

    mysql_query("SELECT COUNT(*), MONTH(`dPostDateTime`) AS `month`, DATE_FORMAT(DATE(`dPostDateTime`), '%W, %b, %e') AS `day`, DATE(`dPostDateTime`) AS 'date' FROM `tblQA` WHERE cCategory IN ('Football','Baseball','Basketball','Hockey') AND dPostDateTime >= '2010-08-01' AND dPostDateTime <= '2011-07-31' GROUP BY `month`");
    

    Then, if you want your results to be ordered by the month as well, so the table goes in a cronological order, you’d want to add ORDER BY month in there as well, assuming it exists (as in example 1) or you’re creating it (as in example 2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying the following query and get only zero results (I am supposed
I am trying to get the results of this code this way: title: Ben
I am using Entity Framework. I am trying to get the results from linq
I'm trying to build up a string array in JavaScript and get the results
I am a bit puzzled with my Regex results (and still trying to get
I have a 3 tables that I'm trying to join and get distinct results.
I'm trying to use $.post within a function, get the results, then return the
I'm trying to use the jQuery get function to render the results of an
I am trying to get a data sorted from 2 tables posts and postmeta
Given: case class Person(name: String) and trying to do: scala> List(Person(Tom), Person(Bob)).sorted results in

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.