如何从我的数据库(PHP)获取确切的列和行值?

时间:2015-11-05 18:32:42

标签: php mysql

     id      timing     temp    temp1   temp2   temp3
   5260     1446746934  -76     -15      4       25
    5259    1446746332  -75     -14      5      25
    5258    1446745731  -77     -15      6      25

我有这样的数据库。我编写了下面的代码来从我的数据库中获取行值。我想从以前的点获得数据。现在,我只从临时列中得到最新的-76点。如何从以前的点获取数据,如-75或-77在一列?

  $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

2 个答案:

答案 0 :(得分:0)

试试这个:

$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;
}

" echo $ te"在循环之外,结果是完整的但是你的代码只打印查询执行返回的最后一条记录。

答案 1 :(得分:0)

我能做的最好的方法是在我的数据库站点上做更多的代码来逐个获取数据。我知道这不是正确的做法。但至少这是我能为我的计划做的最好的事情。