Hey Jason, with some direction from Ray, I have modified what I was doing...I just wanted to make sure that the calculation is correct.
so therefore for finding out the most popular product category...would this calculation work (its hard to test without having to manually go through all the orders in the database and work out the math lol)
$result = mysql_query('SELECT CategoryName FROM orderdetails INNER JOIN products ON orderdetails.DetailProductID = products.ProductID INNER JOIN productcategories ON products.ProductCategoryID = productcategories.CategoryID GROUP BY productcategories.CategoryName ORDER BY Count(*) DESC LIMIT 1') or die(mysql_error());
$PopularCategory = mysql_fetch_assoc($result);
Also for using the above and modifying to find results using dates...how would I calculate say for example - the revenue for the previous month then also for the current month....reason why i ask is the example you gave yesterday regarding to calculate the sum by month is the result gave a very unusual value since I was able to calculate the result manually it doesnt match the result from the recordset query.
Chris
I need to double check result.. but I think I worked out the date in terms of popular month for transactions:
<?php
$result = mysql_query('SELECT OrderDate FROM orders GROUP BY DATE_FORMAT(OrderDate, "%m") ORDER BY Count(*) DESC LIMIT 1') or die(mysql_error());
$PopularMonth = mysql_fetch_assoc($result);
?>
Then to display this result:
<?php echo date('M',strtotime($PopularMonth['OrderDate'])); ?>