Hi guys!
I am having a complete mare and now can't see the wood for the trees!!
I have a table which holds orders - I want to be able to see how many times each customer has ordered, and when they last ordered.
I am there apart from the last time they ordered. Currently the date of their first order is returned, as the query takes the first date is comes to.
I am thinking that I will need to set up a new SQL query to run before I run the below, but my brain is completely mashed at the moment, so any help will be gratefully received!
$query = "SELECT orders_id, customers_id, count(*) AS number_of_orders, customers_name, customers_company, DATE_FORMAT(date_purchased, '%M %D %Y') AS purchase_date FROM orders GROUP BY customers_company";
$result = @mysql_query($query);
if ($result) {
echo '<table width="100%" align=center>
<tr><td valign=top><b>Company Name</b></td><td width="20%" align=center valign=top><b>Number of Orders</b></td><td width="5%"> </td><td width="30%" valign=top><b>Date of Last Order</b></td></tr>';
while ($order_stats = mysql_fetch_array($result)) {
if ($order_stats[customers_company] !="") {
if ($order_stats[customers_company] ==".") {
echo '<tr><td valign=top>=' . $order_stats[customers_name] . '</td><td align=center valign=top>' . $order_stats[number_of_orders] . '</td><td> </td><td valign=top>' . $order_stats[purchase_date] . '</td></tr>';
echo '<tr><td colspan=4 align=left><hr size=1 width="97%" color=336699></td></tr>';
} else {
echo '<tr><td valign=top>' . $order_stats[customers_company] . '</td><td align=center valign=top>' . $order_stats[number_of_orders] . '</td><td> </td><td valign=top>' . $order_stats[purchase_date] . '</td></tr>';
echo '<tr><td colspan=4 align=left><hr size=1 width="97%" color=336699></td></tr>';
}
} else {
echo '<tr><td valign=top>' . $order_stats[customers_name] . '</td><td align=center valign=top>' . $order_stats[number_of_orders] . '</td><td> </td><td valign=top>' . $order_stats[date] . '</td></tr>';
echo '<tr><td colspan=4 align=left><hr size=1 width="97%" color=336699></td></tr>';
}
}
echo '</table>';
}
I am having a complete mare and now can't see the wood for the trees!!
I have a table which holds orders - I want to be able to see how many times each customer has ordered, and when they last ordered.
I am there apart from the last time they ordered. Currently the date of their first order is returned, as the query takes the first date is comes to.
I am thinking that I will need to set up a new SQL query to run before I run the below, but my brain is completely mashed at the moment, so any help will be gratefully received!
$query = "SELECT orders_id, customers_id, count(*) AS number_of_orders, customers_name, customers_company, DATE_FORMAT(date_purchased, '%M %D %Y') AS purchase_date FROM orders GROUP BY customers_company";
$result = @mysql_query($query);
if ($result) {
echo '<table width="100%" align=center>
<tr><td valign=top><b>Company Name</b></td><td width="20%" align=center valign=top><b>Number of Orders</b></td><td width="5%"> </td><td width="30%" valign=top><b>Date of Last Order</b></td></tr>';
while ($order_stats = mysql_fetch_array($result)) {
if ($order_stats[customers_company] !="") {
if ($order_stats[customers_company] ==".") {
echo '<tr><td valign=top>=' . $order_stats[customers_name] . '</td><td align=center valign=top>' . $order_stats[number_of_orders] . '</td><td> </td><td valign=top>' . $order_stats[purchase_date] . '</td></tr>';
echo '<tr><td colspan=4 align=left><hr size=1 width="97%" color=336699></td></tr>';
} else {
echo '<tr><td valign=top>' . $order_stats[customers_company] . '</td><td align=center valign=top>' . $order_stats[number_of_orders] . '</td><td> </td><td valign=top>' . $order_stats[purchase_date] . '</td></tr>';
echo '<tr><td colspan=4 align=left><hr size=1 width="97%" color=336699></td></tr>';
}
} else {
echo '<tr><td valign=top>' . $order_stats[customers_name] . '</td><td align=center valign=top>' . $order_stats[number_of_orders] . '</td><td> </td><td valign=top>' . $order_stats[date] . '</td></tr>';
echo '<tr><td colspan=4 align=left><hr size=1 width="97%" color=336699></td></tr>';
}
}
echo '</table>';
}