zavin Posted July 11, 2008 Share Posted July 11, 2008 I am wanting to get a total of all payment made in a month. For example June would = all payments made in June. My database has the following feilds: payment_id, user_id, txn_id, item, payment_date, payment_status, payment_gross, payment_type, mcgross, quantity, payer_id, payer_status, payer_email, payer_businessname The code I am using right now is: $sql = "SELECT sum( mcgross ) AS `total` FROM `payments`WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) <= FROM_UNIXTIME(`payment_date`)"; $rs_result = mysql_query ($sql); while ($row = mysql_fetch_assoc($rs_result)) echo "$".$row['total']."; Doing it this way only shows the last 30 days. Does anyone know of a good solution? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 12, 2008 Share Posted July 12, 2008 ...WHERE MONTH(FROM_UNIXTIME(`payment_date`)) = 6 Quote Link to comment Share on other sites More sharing options...
zavin Posted July 12, 2008 Author Share Posted July 12, 2008 Your response was not very clear. I tryed: $sql = "SELECT sum( mcgross ) AS `total` FROM `payments`WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) WHERE MONTH(FROM_UNIXTIME(`payment_date`)) = 6"; And: $sql = "SELECT sum( mcgross ) AS `total` FROM `payments`WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) <= FROM_UNIXTIME(`payment_date`)WHERE MONTH(FROM_UNIXTIME(`payment_date`)) = 6"; Neither of these gave me the results I was looking for. What exactly are you trying to tell me to replace? Quote Link to comment Share on other sites More sharing options...
zavin Posted July 13, 2008 Author Share Posted July 13, 2008 Can someone explain to me why a php question got moved to a database discussion? The database is working fine. I am having a problem getting the php coded correctly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.