請認準此查詢:result_array()的ActiveRecord在笨
$this->db->select('users.user_id, user_info.name, user_info.fam ,user_type.type_name ');
$this->db->from('user_info');
$this->db->join('users', 'users.user_id = user_info.user_id');
$this->db->join('user_type', 'users.usr_typ_id = user_type.user_type');
$data= $this->db->get()->result_array();
var_dump($data);
echo "<hr>";
foreach ($data as $row);
{
echo $row->user_id ."|";
echo $row->name ."|";
echo $row->fam ."|";
echo $row->type_name ."|".'<br>';
echo "<hr>";
}
的結果:
後續代碼var_dump($ data)返回以下行
array(2) { [0]=> array(4) { ["user_id"]=> string(8) "92090001" ["name"]=> string(5) "parsa" ["fam"]=> string(5) "arian" ["type_name"]=> string(13) "Administrator" } [1]=> array(4) { ["user_id"]=> string(8) "92090002" ["name"]=> string(6) "pendar" ["fam"]=> string(6) "pajouh" ["type_name"]=> string(7) "Blogger" } }
但在「的foreach「部分每行顯示以下錯誤:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/user_model.php
Line Number: 47
如果有人能幫助我,我會很感激。
什麼行代碼是行47號 – sas