I currently have this code:
$query = query("SELECT SUM(ER_read)
FROM tblEread
WHERE ER_ID='$sensor'
AND MONTH(ER_date) = '$thisMonth2[1]'
AND YEAR(ER_date) = '$thisMonth2[0]'
GROUP BY ER_ID");
while($data = fetch_assoc($query))
{
$return[0]['data'][] = Array(1,$data['SUM(ER_read)']);
}
which I’m using to try and add all of the ER_read results together and then store it in an array. My problem is that the array isn’t displaying the sum of the ER_read, and if I echo the array it only displays the number one and misses out the SUM section completely..
Am I doing something wrong?
I am not sure what you are trying to achieve. If you want to just push the SUM in data and keep it as array for each row then this will work:
If you wanted the array to start with 1 as index and not 0, you would do: