$sensor = Yii::app()->zdb->createCommand("select * from tbl_sensor where stype=2 and nid=$nid order by timestamp desc limit 10")->queryAll();
if($sensor)
{ return $sensor->sdata/10; }
else
{ return null; }
答案 0 :(得分:0)
QueryAll是返回数组。像这样使用
foreach($sensor as $key => $row) {
$yourvar = $row['sdata'];
}
答案 1 :(得分:0)
QueryAll将为您提供数组数组..
获取所有列:
$sensor = Yii::app()->zdb->createCommand("select * from tbl_sensor where stype=2 and nid=$nid order by timestamp desc limit 10")->queryAll();
if($sensor) {
foreach($sensor as $data_row) {
foreach($data_row as $data_key => $data_value) {
echo "$data_key: $data_value\n";
}
}
}
else {
return null;
}
获取sdata:
$sdata_values = Yii::app()->zdb->createCommand("select sdata from tbl_sensor where stype=2 and nid=$nid order by timestamp desc limit 10")->queryColumn();
if($sdata_values) {
foreach($sdata_values as $sdata_value) {
echo $sdata_value / 10;
}
}
else {
return null;
}