Total for the month

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zavin
Forum Newbie
Posts: 11
Joined: Fri Feb 29, 2008 6:28 pm

Total for the month

Post 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>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Total for the month

Post 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`);
Post Reply