Note that there are some explanatory texts on larger screens.

plurals
  1. POphp code of troubling getting multiple value
    primarykey
    data
    text
    <p>I have codes that should be getting value from mysql database, I can get only one value but I have while loop so it can get value and output data separated with comma. But I only get one value and cannot get multiple value. the result should be like this, // End main PHP block. Data looks like this: [ [123456789, 20.9],[1234654321, 22.1] ] here is the code:</p> <pre><code>&lt;?php // connect to MySQL mysql_connect('localhost','','') or die("Can't connect that way!"); @mysql_select_db('temperature1') or die("Unable to select a database called 'temperature'"); if(ISSET($_GET['t']) &amp;&amp; (is_numeric($_GET['t'])) ){ // message from the Arduino $temp = $_GET['t']; $qry = "INSERT INTO tempArray(timing,temp) VALUES(".time().",'$temp')"; echo $qry; mysql_query($qry); mysql_close(); exit('200'); } // no temp reading has been passed, lets show the chart. $daysec = 60*60*24; //86,400 $daynow = time(); if(!$_GET['d'] || !is_numeric($_GET['d'])){ $dayoffset = 1; } else { $dayoffset = $_GET['d']; } $dlimit = $daynow-($daysec*$dayoffset); $qryd = "SELECT id, timing, temp FROM tempArray WHERE timing&gt;='$dlimit' ORDER BY id ASC LIMIT 1008"; // 1008 is a weeks worth of data, // assuming 10 min intervals $r = mysql_query($qryd); $count = mysql_num_rows($r); $i=0; $r = mysql_query($qryd); $count = mysql_num_rows($r); while($row=mysql_fetch_array($r, MYSQL_ASSOC)) { $tid=$row['id']; $dt = ($row['timing']+36000)*1000; $te = $row['temp']; if($te&gt;$maxtemp) $maxtemp=$te; // so the graph doesnt run along the top if($te&lt;$mintemp) $mintemp=$te; // or bottom of the axis $return="[$dt, $te]"; echo $return; //here I get all values [1385435831000, 21][1385435862000, 23][1385435892000, 22][1385435923000, 25][1385435923000, 22] $i++; if($i&lt;$count) $return= ","; echo $return; // if there is more data, add a ',' however, it return me ,,,[1385435923000, 22] $latest = "$dt|$te"; // this will get filled up with each one } mysql_close(); // convert $latest to actual date - easier to do it here than in javascript (which I loathe) $latest = explode('|',$latest); $latest[0] = date('g:ia, j.m.Y',(($latest[0])/1000)-36000); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload