Jump to content


Photo

Getting current month and displaying result on Chart


Best Answer dapcigar, 04 July 2014 - 05:43 AM

Nevermind, i fixed it. incase someone elese needs the solution

 MONTH(date) = MONTH(CURRENT_DATE)
Go to the full post


  • Please log in to reply
4 replies to this topic

#1 dapcigar

dapcigar

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 04 July 2014 - 04:32 AM

Hello all,

 

Am trying to calculate some data and display the result of the current month in a chart form. i just don't know how to get the current month. this is not working..

<?php
include('mysql_connect.php');

$date = 'MONTH(CURRENT_DATE())';
$status = 'paid';
//mysql_select_db("hyprops", $con);

$query = mysql_query("SELECT sum(amount) 'amount',  department FROM requisition WHERE status = '$status' AND  date='$date' ");

$category = array();
$category['name'] = 'department';

//$series1 = array();
//$series1['name'] = 'actual';

$series2 = array();
$series2['name'] = 'amount';

//$series3 = array();
//$series3['name'] = 'Highcharts';


while($r = mysql_fetch_array($query)) {
    $category['data'][] = $r['department'];
   // $series1['data'][] = $r['actual'];
    $series2['data'][] = $r['amount'];
  //  $series3['data'][] = $r['highcharts'];   
}

$result = array();
array_push($result,$category);
//array_push($result,$series1);
array_push($result,$series2);
//array_push($result,$series3);


print json_encode($result, JSON_NUMERIC_CHECK);

mysql_close($con);
?> 

Please how can i solve this issue?

 

Thanks in advance



#2 dapcigar

dapcigar

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 04 July 2014 - 05:43 AM   Best Answer

Nevermind, i fixed it. incase someone elese needs the solution

 MONTH(date) = MONTH(CURRENT_DATE)


#3 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,636 posts

Posted 04 July 2014 - 08:49 AM

your solution will get data from every matching month, ..., 2012-07, 2013-07, 2014-07.

 

if you really only want the current month, you need to match both the current year and the current month.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#4 dapcigar

dapcigar

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 09 July 2014 - 08:12 AM

oh really? so how do i do that?

 

thanks in advance



#5 maxxd

maxxd

    Advanced Member

  • Members
  • PipPipPip
  • 149 posts
  • LocationNorth Carolina

Posted 09 July 2014 - 11:02 AM

"WHERE MONTH(date) = MONTH(CURRENT_DATE) AND YEAR(date) = YEAR(CURRENT_DATE)" should do it.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com