对象和数组的麻烦

时间:2017-11-10 11:30:27

标签: php arrays object

从数组中获取单个数据时遇到问题。搜索互联网大约2个小时没有成功。代码如下:

$id_name = $this->name->Text;
$finder = prdtblRecord::finder();
$result = $finder->findAllByname($id_name);
$row_cnt = count($result);

if($row_cnt == 0)
{
    $this->failed_id($param);
}

if($row_cnt == 1)
{
    $this->id->Text = $result->id;
    $this->name->Text = $result->name;
    $this->adresse->Text = $result->adresse;
    $this->plz->Text = $result->plz;
    $this->ort->Text = $result->ort;
    $this->firma->Text = $result->firma;
}

问题涉及$result->id。 错误是Trying to get property of non-object

感谢您的回复和最诚挚的问候。

1 个答案:

答案 0 :(得分:1)

我怀疑你有多个对象尝试添加[0]

$this->id->Text = $result[0]->id;