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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:18:31+00:00 2026-06-14T17:18:31+00:00

How could I added the option to show the statistics for last month. PHP

  • 0

How could I added the option to show the statistics for last month.

PHP

public function chart() {
    $this->load->language('common/home');

    $data = array();

    $data['order'] = array();
    $data['customer'] = array();
    $data['xaxis'] = array();

    $data['order']['label'] = $this->language->get('text_order');
    $data['customer']['label'] = $this->language->get('text_customer');

    if (isset($this->request->get['range'])) {
        $range = $this->request->get['range'];
    } else {
        $range = 'month';
    }

    switch ($range) {
        case 'day':
            for ($i = 0; $i < 24; $i++) {
                $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND (DATE(date_added) = DATE(NOW()) AND HOUR(date_added) = '" . (int)$i . "') GROUP BY HOUR(date_added) ORDER BY date_added ASC");

                if ($query->num_rows) {
                    $data['order']['data'][]  = array($i, (int)$query->row['total']);
                } else {
                    $data['order']['data'][]  = array($i, 0);
                }

                $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE DATE(date_added) = DATE(NOW()) AND HOUR(date_added) = '" . (int)$i . "' GROUP BY HOUR(date_added) ORDER BY date_added ASC");

                if ($query->num_rows) {
                    $data['customer']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['customer']['data'][] = array($i, 0);
                }

                $data['xaxis'][] = array($i, date('H', mktime($i, 0, 0, date('n'), date('j'), date('Y'))));
            }                   
            break;
        case 'week':
            $date_start = strtotime('-' . date('w') . ' days'); 

            for ($i = 0; $i < 7; $i++) {
                $date = date('Y-m-d', $date_start + ($i * 86400));

                $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND DATE(date_added) = '" . $this->db->escape($date) . "' GROUP BY DATE(date_added)");

                if ($query->num_rows) {
                    $data['order']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['order']['data'][] = array($i, 0);
                }

                $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "customer` WHERE DATE(date_added) = '" . $this->db->escape($date) . "' GROUP BY DATE(date_added)");

                if ($query->num_rows) {
                    $data['customer']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['customer']['data'][] = array($i, 0);
                }

                $data['xaxis'][] = array($i, date('D', strtotime($date)));
            }

            break;
        default:
        case 'month':
            for ($i = 1; $i <= date('t'); $i++) {
                $date = date('Y') . '-' . date('m') . '-' . $i;

                $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND (DATE(date_added) = '" . $this->db->escape($date) . "') GROUP BY DAY(date_added)");

                if ($query->num_rows) {
                    $data['order']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['order']['data'][] = array($i, 0);
                }   

                $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE DATE(date_added) = '" . $this->db->escape($date) . "' GROUP BY DAY(date_added)");

                if ($query->num_rows) {
                    $data['customer']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['customer']['data'][] = array($i, 0);
                }   

                $data['xaxis'][] = array($i, date('j', strtotime($date)));
            }
            break;
        case 'year':
            for ($i = 1; $i <= 12; $i++) {
                $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND YEAR(date_added) = '" . date('Y') . "' AND MONTH(date_added) = '" . $i . "' GROUP BY MONTH(date_added)");

                if ($query->num_rows) {
                    $data['order']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['order']['data'][] = array($i, 0);
                }

                $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE YEAR(date_added) = '" . date('Y') . "' AND MONTH(date_added) = '" . $i . "' GROUP BY MONTH(date_added)");

                if ($query->num_rows) { 
                    $data['customer']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['customer']['data'][] = array($i, 0);
                }

                $data['xaxis'][] = array($i, date('M', mktime(0, 0, 0, $i, 1, date('Y'))));
            }           
            break;  
    } 

    $this->response->setOutput(json_encode($data));
}

HTML

<select name="range">
    <option value="day">Today</option>
    <option value="week">This Week</option>
    <option value="month">This Month</option>
    <option value="year">This Year</option>
</select>   

Qvmod answer from @Andy:

<file name="admin/controller/common/home.php">
    <operation>
           <search position="before"><![CDATA[case 'year':]]></search>
           <add><![CDATA[

        case 'month_previous':
            for ($i = 1; $i <= date('t', strtotime(date('Y-m', strtotime('-1 month')).'-01')); $i++) {
                $date = date('Y-m', strtotime('-1 month')).'-'.$i;

                $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND (DATE(date_added) = '" . $this->db->escape($date) . "') GROUP BY DAY(date_added)");

                if ($query->num_rows) {
                    $data['order']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['order']['data'][] = array($i, 0);
                }   

                $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE DATE(date_added) = '" . $this->db->escape($date) . "' GROUP BY DAY(date_added)");

                if ($query->num_rows) {
                    $data['customer']['data'][] = array($i, (int)$query->row['total']);
                } else {
                    $data['customer']['data'][] = array($i, 0);
                }   

                $data['xaxis'][] = array($i, date('j', strtotime($date)));
            }
        break;

        ]]></add>
       </operation>
</file>
<file name="admin/view/template/common/home.tpl">
    <operation>
        <search position="after"><![CDATA[<option value="month"><?php echo $text_month; ?></option>]]></search>
        <add><![CDATA[          
            <option value="month_previous">Last Month</option>
        ]]></add>
    </operation>
</file>
  • 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-14T17:18:32+00:00Added an answer on June 14, 2026 at 5:18 pm

    Create a new HTML option

        <option value="last_month">Last Month</option>
    

    Then add in a new switch case for your last_month option. You can do this by copying the month case from the case ‘month’ line to the break;.

    In the for loop change date(‘t’) to:

        date('t', strtotime(date('Y-m', strtotime('-1 month')).'-01'))
    

    This will allow you to get last months number of days, then the last bit you should have to change will be the $date var. in a similar way to above:

        $date = date('Y-m', strtotime('-1 month')).'-'.$i;
    

    This should allow you to see all your stats for the previous month.

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

Sidebar

Related Questions

What features could be added to a new programming language to make it more
I added the following function so I could iterate backwards over some collections: jQuery.reverseEach
I've added an object to the XsltArgumentList. I was wondering how I could access
Could someone please tell me why this <%= destroy_password_url @user.password_reset_token %> generates http://localhost:3000/api/destroy_password.4G5EoRVYMUAtiIKqOerKsw routes.rb
Could this be done with javascript/jQuery : <div class=number>99,123,123</div> <div class=number>123,123,123</div> <div class=number>1,123,123,123</div> <div
Could someone please suggest why this is happening... I’ve got some code to pretty
could somebody please take a look at this http://jsfiddle.net/bloodygeese/EzkFR/1/ My aim is to on
I could be missing something severely here, but this is just not adding up.
I've not sure if this could be implemented with Subversion, but is there a
This could turn out to be the dumbest question ever. I want to track

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.