Jump to content
luhlacom

PHP - Total sales (year, month) sql query

Recommended Posts

Hi,  

in Prestashop SQL Manager I have query for total sales by month, year. How I can view in PHP table ? I use Prestashop 1.6.

Function query in SQL Manager:

SELECT 
  year(date_add),date_format(date_add,'%M'),count(id_order), sum(total_paid) 
  FROM ps_orders 
  WHERE year(date_add) > 2018
  GROUP BY year(date_add),month(date_add) 
  ORDER BY year(date_add),month(date_add)

IN PHP File: (not working for me)

$data = Db::getInstance()->ExecuteS(' 
SELECT 
  year(date_add),date_format(date_add,'%M'),count(id_order), sum(total_paid) 
  FROM ps_orders 
  WHERE year(date_add) > 2018
  GROUP BY year(date_add),month(date_add) 
  ORDER BY year(date_add),month(date_add)dd)
       ');   
 
echo "Počet objednávek: ";
echo '<section class="table1"><table>';
         foreach($data as $order)
    {  
         
         echo '<td>"'.$order['date_add'].'"</td>';
         echo '<td>"'.$order['date_add'].'"</td>';
         echo '<td>"'.$order['id_order'].'"</td>';
         echo '<td>"'.$order['total_paid'].'"</td>';
echo '</table></section>';
    }

Thanks you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More