I'm trying to get the averages for a range of data in between two dates into 20 averaged results for a graph but I am having problems with LIMIT i am dividing the number of results by 20(points on graph) then rounding the number so that I can set the limit and the offset to get the relevant data. My problem is as so as the offset is above 0 it doesn't return any results, any help would be much appreciated.
$query = "SELECT COUNT(id) FROM tblbreaker10 WHERE date1 > startdate AND date2 < enddate";
$result = mysql_query($query);
$count = mysql_fetch_row($result);
$count = ($count[0] / 20);
$count = round($count);
$limit = $count;
$offset = 0;
for($i = 0;$i < 20;$i++)
{
$query = "SELECT
AVG(ampr) AS ampr_avg,
AVG(ampy) AS ampy_avg,
AVG(ampb) AS ampb_avg,
AVG(ampbl) AS ampbl_avg,
AVG(vry) AS vry_avg,
AVG(vrb) AS vrb_avg,
AVG(vyb) AS vyb_avg,
AVG(vrn) AS vrn_avg,
AVG(vyn) AS vyn_avg,
AVG(vbn) AS vbn_avg,
AVG(kw) AS kw_avg,
AVG(pf) AS pf_avg
FROM tblbreaker10
WHERE date1 > startdate AND date2 < enddate
LIMIT $offset, $limit";
echo $query;
$result = mysql_query($query);
while($row = mysql_fetch_array($result)):
echo "ampr_avg=" . $row[ampr_avg] . "&";
echo "ampy_avg=" . $row[ampy_avg] . "&";
echo "ampb_avg=" . $row[ampb_avg] . "&";
echo "ampbl_avg=" . $row[ampbl_avg] . "&";
echo "vry_avg=" . $row[vry_avg] . "&";
echo "vrb_avg=" . $row[vrb_avg] . "&";
echo "vyb_avg=" . $row[vyb_avg] . "&";
echo "vrn_avg=" . $row[vrn_avg] . "&";
echo "vyn_avg=" . $row[vyn_avg] . "&";
echo "vbn_avg=" . $row[vbn_avg] . "&";
echo "kw_avg=" . $row[kw_avg] . "&";
echo "pf_avg=" . $row[11] . "&\n";
endwhile;
mysql_free_result($result);
$offset = ($offset + $count);
}