【发布时间】:2016-11-12 09:52:26
【问题描述】:
我正在从名为properties 的表中获取json 数据。列名为 attr,其中包含 size、bedrooms 和 prop-type。
$q= mysqli_query($connect,"SELECT * FROM properties");
$savemyval = array();
while($row= mysqli_fetch_assoc($q)){
$data = json_decode($row['attr']);
//var_dump($data);
if($proptpe == $data->proptype){
$savemyval[] = $row['id'];
}
}
如果我 var_dump 这就是我得到的,像上面一样查询数据
object(stdClass)[3]
public 'bedrooms' => string '5' (length=1)
public 'proptype' => string 'residential' (length=11)
object(stdClass)[4]
public 'bedrooms' => string '4' (length=1)
public 'proptype' => string 'commercial' (length=10)
object(stdClass)[3]
public 'size' => string '16000' (length=5)
public 'prop-type' => string 'commercial' (length=10)
在 var_dump 中我得到了正确的数据,但是当我尝试获取 proprtype 时,如果它大于 1,它会给我错误
PHP : 注意:未定义的属性:stdClass::
如果我使用 isset 则没有错误,但它仍然会打印一个结果,而转储给我的结果不止 1 个
【问题讨论】: