I have a database of orders - the below code is supposed to give me a list of the months that have orders. Each month links to a page showing all the orders for that month. The table also includes sales totals for each month. It is only showing the current month, though. What is wrong? Thanks! <?php $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db); $result = mysql_query("SELECT DISTINCT year FROM orders ORDER BY year DESC"); while($row = mysql_fetch_array($result)) { $year = $row['year']; $result = mysql_query("SELECT DISTINCT month FROM orders WHERE year='$year' ORDER BY month DESC"); while($monthrow = mysql_fetch_array($result)) { $month = $monthrow['month']; $result = mysql_query("SELECT * FROM orders WHERE year='$year' && month='$month' ORDER BY orderid DESC"); while($orderrow = mysql_fetch_array($result)) { $monthlyordertotal = $monthlyordertotal + $orderrow['subtotal']; } echo "<tr><td><a href=month.php?month=".$monthrow['month']."&year=$year>".$monthrow['month']." - $year</a></td><td>$$monthlyordertotal</td></tr>"; } } ?> PHP:
From your code it looks like it is fetching months for a single year. So if it is fetching 2009, perhaps it has only data for January.