don't know why this function not working
function sumAll($row ,$monthNr, $first){
$data = "SELECT SUM($row) FROM closeDay WHERE MONTH(dates) = $monthNr AND YEAR(dates) = YEAR(CURDATE())";
$result = mysql_query($data);
$query_data = mysql_fetch_row($result);
$first = $query_data[0];
return $first;
}
//calling the function
sumAll('total' , 01, $first);
help please thanks
you have non sence parameters in your function, try this:
function sumAll($row,$monthNr){
$data = "SELECT SUM(".$row.") sums FROM closeDay WHERE MONTH(dates) = '".$monthNr."' AND YEAR(dates) = YEAR(CURDATE())";
$result = mysql_query($data);
$query_data = mysql_fetch_array($result);
$first = $query_data['sums'];
return $first;
}
call it like that:
sumAll('total' , 01);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.