【发布时间】:2015-03-29 07:37:13
【问题描述】:
我这里有一些错误
我想使用嵌套的foreach 组合来自 2 个查询的数据,并将数据保存在一个名为 result 的数组中,但在这部分代码中存在错误Trying to get property of non-object:'id_product'=>$detail_result->ID,
谁能帮帮我?
我还是新手,使用 yii 框架 php
这是我的代码
$result = 数组();
$criteria = new CDbCriteria;
$criteria->condition = 'date_time >= :start and date_time <= :end';
$criteria->order = 'date_time';
$criteria->params = array(':start' => $_POST['tanggal']['start'] ,':end' => $_POST['tanggal']['end']);
$checkIn = CheckIn::model()->findAll($criteria);
foreach($checkIn as $entry) {
$sql = "select * from check_in_detail where ID_check_in = $entry->ID";
$detail_results = Yii::app()->db->createCommand($sql)->queryAll();
foreach($detail_results as $detail_result)
{
$result [] = array(
'tanggal'=>$entry->date_time,
'id_product'=>$detail_result->ID,
'total'=>$detail_result->total,
'id_distributor'=>$entry->iDDistributor->name,
'other'=>$entry->description,
);
}
}
有人可以帮忙吗? 谢谢
【问题讨论】:
标签: php yii foreach frameworks nested