如何在CakePHP ctp文件中查看来自MySQL的数组数据?

时间:2017-05-04 14:49:11

标签: mysql arrays cakephp foreach

我想在CakePHP ctp文件中使用数组查看MySQL数据。我无法理解的代码中的错误是什么?

$this->loadModel('MacHistory');
$data = $this->MacHistory->find('all', array('conditions' => array('package_customer_id' => $pcid)));   

$filteredData = array();
foreach ($data as $single) {
    $mac[] = $single['MacHistory']['mac'];
    $user_id[] = $single['MacHistory']['installed_by'];
    $installation_date[] = $single['MacHistory']['installation_date'];
}

if (!empty($user_id)) {
    $filteredData['mac'] = $mac;
    $filteredData['user_id.'] = $user_id;
    $filteredData['installation_date.'] = $installation_date;    
    $this->request->data['PackageCustomer'] = $filteredData;
}

$this->set(compact('filteredData'));

0 个答案:

没有答案