Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

SQL PHP Help


Guest

Recommended Posts

Hi I am trying to get all the total value of all orders for jan this year the code is the most recent thing i have tried. I always just get the same result, 64. 64 doesnt meen anything. Can anybody see what is up, I run a similar query through phpmyadmin and get the right result?

 

 

$jandate = date("Y-m",strtotime ("-1 month"));
   $query = "SELECT sum(orders_total.value) FROM orders_total, orders WHERE orders.orders_id = orders_total.orders_id AND orders.date_purchased LIKE \"$jandate%\"  AND class = \"ot_total\"";

Link to comment
Share on other sites

Im still not sure about the value delimiters. But i have tried a lot of stuff, even set the dat to next month which doesnt exist yet, I stull get 64, what is up with that. Am i getting this value from somewere else or something. I have also changed the names of fariables etc still get 64.

Link to comment
Share on other sites

Try this:

$sd = mktime(0, 0, 0, 1, 1, 2005); // start date is 1 January 2005
$ed = mktime(0, 0, 0, date("m", $sd)+1, date("d", $sd), date("Y", $sd)); // end date is 1 February 2005
$query = "
SELECT SUM(ot.value) AS total, COUNT(*) AS number 
FROM orders_total ot, orders o  
WHERE o.orders_id=ot.orders_id 
AND o.date_purchased >= '".tep_db_input(date("Y-m-d\TH:i:s", $sd))."' 
AND o.date_purchased <= '".tep_db_input(date("Y-m-d\TH:i:s", $ed))."' 
AND ot.class='ot_total'";

#$result = tep_db_fetch_array(tep_db_query($query));
#echo 'Total for time period: <b>' .tep_db_input(date("Y-m-d", $sd)) . '</b> - <b>' . tep_db_input(date("Y-m-d", $ed)) . '</b><br>';
#echo 'Number of orders: <b>' . $result['number'] . '</b><br>';
#echo 'Total of orders: <b>' . $result['total'] . '</b><br>';
#echo  '<br>Code courtesy of Chemo';

 

Bobby

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...