Is there a way to return every Nth record of a MySQL request while keeping my descending limit? Otherwise, is it possible to only save every Nth request into my PHP array? The data is eventually echoed to javascript to supply data to a Google Chart, and obviously 10080 records does not create a smooth graph.
$myquery = "SELECT *
FROM (
SELECT
@row := @row +1 AS rownum, dateTime, outTemp, dewpoint
FROM (
SELECT @row :=0) r, archive
) ranked
WHERE rownum % 5 = 1";
$query = mysql_query($myquery);
if ( ! $query )
{
echo mysql_error();
die;
}
$table=array();
$table['cols'] = array(
// Chart Labels (i.e. column headers)
array('label' => 'dateTime', 'type' => 'number'),
array('label' => 'Temp', 'type' => 'number'),
array('label' => 'Dew', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($query))
{
$temp = array();
$temp[] = array('v' => (int) $r['dateTime']);
$temp[] = array('v' => (int) $r['outTemp']);
$temp[] = array('v' => (int) $r['dewpoint']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
UPDATE:
I can select every Nth row using the instructions at How do you select every n-th row from mysql but it does not solve how to keep my descending filter. I am trying to select the last x rows of my dataset in a manner like using DESC LIMIT 10