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

  • Home
  • SEARCH
  • 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 8067205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:13:01+00:00 2026-06-05T12:13:01+00:00

I have a table with this structure: table name: customer_history id| orders | order_date

  • 0

I have a table with this structure:

table name: customer_history

id| orders | order_date (timestamp) |  status    |  
--------------------------------------------------
 1|   1    | 2012-05-29 13:11:59    |  active    |
 2|   1    | 2012-05-29 13:11:59    |  active    |
 3|   1    | 2012-05-30 13:11:59    |  canceled  |
 4|   1    | 2012-05-31 13:11:59    |  trialing  |

I need to query the db and count the number of total orders, where status != canceled, for each day, going back one calendar month, and assign a unique variable to each daily total.

Yesterday’s order total would be something like $day-1, two days ago $day-2, etc.

EDIT Answer below.

$query = "SELECT 
            COUNT(*) AS number, 
            DATE(order_date) AS order_day 
        FROM 
            customer_history
        WHERE 
            status <> 'canceled' 
        GROUP BY 
            order_day 
        ORDER BY 
            order_date 
        DESC
        LIMIT 31";

$result = mysql_query($query) or die(mysql_error());

$i = 1;
$days = array();

while($row = mysql_fetch_assoc($result)) {

      $days[$i] = $row;
      $i++;
}

echo $days[1]['number'];
echo $days[2]['number'];
echo $days[3]['number'];
echo $days[4]['number'];
echo $days[5]['number'];
echo $days[6]['number'];
  • 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-05T12:13:02+00:00Added an answer on June 5, 2026 at 12:13 pm
    SELECT COUNT(*) AS number, DATE(order_date) AS order_day FROM orders WHERE status <> 'canceled' GROUP BY order_day ORDER BY order_date DESC LIMIT 31
    

    Then just loop over the results. First one is the current day, second is yesterday, third is day before yesterday, etc.

    EDIT

    Including loop/variables:

        <?php
    
    $query = "SELECT 
                    COUNT(*) AS number, 
                    DATE(order_date) AS order_day 
                FROM 
                    orders 
                WHERE 
                    status <> 'canceled' 
                GROUP BY 
                    order_day 
                ORDER BY 
                    order_date 
                DESC
                LIMIT 31";
    
        $result = mysql_query($query);
    
        $i = 1;
        $days = array();
    
        while($row = mysql_fetch_assoc($query)
        {
            $days[$i] = $row;
            $i++;
    
        }
    
        ?>
    

    echo $days[1][‘number’] gives you the number of orders for today, $days[2][‘number’] for yesterday, etc. You can output the actual date by echoing $days[x][‘order_day’].

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

Sidebar

Related Questions

I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
Hi i have a table structure like this. table **geoinfo** id name desc I
I have this table structure Product product_id (PK) name Order_Detail order_detail_id product_id quantity Example
I have this table structure, | id | name | level | --------------------- |
I have a question about MySQL. I have this table structure: ID Name ------
I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
I have three tables like this: Table 1 structure: Name: registered_applicant_details Fields: applicant_id INT
I have a MySQL table structured somewhat like this: type name value ===================== 1
I have this table structure and would like to map it using Fluent Hibernate
I have a table structure like this: <table> <tr> <td> <ul> <li class=check></li> </ul>

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.