id timing temp temp1 temp2 temp3
5260 1446746934 -76 -15 4 25
5259 1446746332 -75 -14 5 25
5258 1446745731 -77 -15 6 25
I have database like this. And I wrote the code below to get the row value out from my database. I would like to get the data from the previous points. Right now, I only get the latest point -76 from temp column. How to get the data from previous points like -75 or -77 at one column ??
$qryd = "SELECT id, timing, temp,temp1,temp2,temp3 FROM tempArray WHERE timing>='$dlimit' ORDER BY id ASC LIMIT 1008;
$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'];
$te = $row['temp'];
$return="[$dt, $te],";
echo $return;
$i++;
}
echo $te;
//the result is -76
Try this:
$qryd = "SELECT id, timing, temp,temp1,temp2,temp3 FROM tempArray";
$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'];
$te = $row['temp'];
$return="[$dt, $te],";
echo $return;
$i++;
echo $te;
}
The "echo $te" was outside the loop, so the result was complete but your code prints only the last record returned by the query execution.
The best way I can do is to do more code on my database site to grab data one by one. I know it is not the right way to do it. But at least it is the best I can do to my program.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.