Page 1 of 1

Total for the month

Posted: Sat Jun 14, 2008 11:52 pm
by Zavin
I am using the following code to keep track of purchases. The tracking will return the user, item, month of purchase, total spent, and status of payer. I want to add up all of the purchases made for the month and return that value to the page. My data base is using the standard unix time stamp. Does anyone have any ideas?

Code: Select all

<table width="100%" border="1" cellpadding="5">
<tr><td>User ID</td><td>Item</td><td>Month</td><td>Amount</td><td>Payment<br>Stutus</td><td>Order<br>Stutus</td></tr>
<tr><td colspan="6">&nbsp; </td></tr>
<?
while ($row = mysql_fetch_assoc($rs_result)) {
$sql2 = "SELECT * FROM payments_log WHERE payment_id ='".$row['payment_id']."'";
$rs_result2 = mysql_query ($sql2);
while ($row2 = mysql_fetch_assoc($rs_result2)) {
$month=date(F,$row2["date"])
?>
            <tr>
            <td><? echo $row["user_id"]; ?></td>
            <td><? echo $row["item"]; ?></td>
            <td><? echo $month; ?></td>
            <td>$<? echo $row["mcgross"]; ?>.00</td>
            <td><? echo $row["payer_status"]; ?></td>
            <td><? echo $row["payment_status"]; ?></td>
            </tr>
<?
}
};
?>
</table>

Re: Total for the month

Posted: Sun Jun 15, 2008 12:30 am
by John Cartwright
Good old forums to kill time when I should be working :)

Code: Select all

SELECT SUM(`mcgross`) AS `total`
FROM payments_log
WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) <= FROM_UNIXTIME(`date`);