Author Topic: Payment per month  (Read 400 times)

0 Members and 1 Guest are viewing this topic.

Offline zavinTopic starter

  • Irregular
  • Posts: 40
  • MySql 5.1 | PHP 5.2 | Apache 2.2 | Windows Vista
    • View Profile
Payment per month
« on: July 11, 2008, 07:45:09 PM »
 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:

Code: [Select]
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:
Code: [Select]
$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?

Offline Barand

  • Sen . (ile || sei)
  • Staff Alumni
  • 'Mind Boggling!'
  • *
  • Posts: 15,132
  • Gender: Male
  • php 4.3/5.1 MySql 5.0.1
    • View Profile
Re: Payment per month
« Reply #1 on: July 11, 2008, 08:14:53 PM »
...WHERE MONTH(FROM_UNIXTIME(`payment_date`)) = 6
|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

Offline zavinTopic starter

  • Irregular
  • Posts: 40
  • MySql 5.1 | PHP 5.2 | Apache 2.2 | Windows Vista
    • View Profile
Re: Payment per month
« Reply #2 on: July 11, 2008, 08:27:18 PM »
 Your response was not very clear. I tryed:
Code: [Select]
$sql = "SELECT sum( mcgross ) AS `total` FROM `payments`WHERE DATE_SUB(CURDATE(),INTERVAL 1 MONTH) WHERE MONTH(FROM_UNIXTIME(`payment_date`)) = 6";And:
Code: [Select]
$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?

Offline zavinTopic starter

  • Irregular
  • Posts: 40
  • MySql 5.1 | PHP 5.2 | Apache 2.2 | Windows Vista
    • View Profile
Re: Payment per month
« Reply #3 on: July 13, 2008, 02:46:26 AM »
 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.