Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Flot MySQL PHP

Name: retarded 2012-02-04 2:12

I need to parse the results of an sql query so I can graph it in flot. The only examples flot gives are of when the data is already in the correct format e.x) [[a,b][a1,b1]].

I am trying to figure out how to turn a sql query of



$sql = "select temp,date from database order by date asc



into


<script type="text/javascript">
$(function () {
    var d2 = [];
 var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];

$.plot($("#placeholder"), [
        {
            data: d2,
            lines: { show: true, fill: true }
        },
]


Any hints? Only thing I could find on google was using python to parse it out.

Name: Anonymous 2012-02-04 3:07



$statement = $dbh->query($sql);
$data = $statement->fetchAll( \PDO::FETCH_ASSOC );

$response = array();
foreach($data as $data_row) {
  $response .= '['.$data_row['temp'].', '.$data_row['date'].'000]';
}

?>
<script type="text/javascript">
var mydata = [ <?=implode(", ", $response)?> ];
</script>


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List