1
我的Codeigniter加入查詢不起作用。在一個函數中只是試圖匹配用戶表中的RC代碼並獲取電子郵件,該函數正常工作,下一個目標是匹配文章表中的電子郵件ID並正確獲取文章,但生病嘗試加入用戶表和文章表我需要從用戶表中獲取用戶姓氏&姓氏,我不知道是否正確或不正確,請查看下面的代碼。控制器部分:codeigniter加入電子郵件查詢問題
public function user_article()
{
$rc=$_GET['rc'];
$data['title'] = "User Article";
if ($this->session->userdata ('is_logged_in')){
$data['profile']=$this->model_users->profilefetch();
$data['results']=$this->article_m->u_article($_GET);
$this->load->view('sd/header',$data);
$this->load->view('sd/user_article', $data);
$this->load->view('sd/footer', $data);
}
else {
}
}
我的模型:
function u_article($rc)
{
$query=$this->db->select('email')->where('rc',$rc['rc'])->get('users');
$result=$query->result_array();
if ($query->num_rows() > 0) {
$row = $query->row_array();
$array = array ('email' => $row['email'], 'a.status' => '1');
$query1=$this->db->select('a.id,title,a.status,description,image,a.email,tags,postdate,firstname,lastname,rc')->join('users u','u.email = a.email','left')->where($array)->get('articles a');
if ($query1->num_rows() > 0) {
foreach ($query1->result() as $row) {
$data[] = $row;
}
return $data;
}
else {return NULL;}
} else {return NULL;}
}
檢查我的代碼,並告訴我,我的錯誤在此先感謝。在查看
錯誤鞋:
A Database Error Occurred
Error Number: 1052
Column 'email' in where clause is ambiguous
SELECT `a`.`id`, `title`, `a`.`status`, `description`, `image`, `a`.`email`, `tags`, `postdate`, `firstname`, `lastname`, `rc` FROM (`articles` a) LEFT JOIN `users` u ON `u`.`email` = `a`.`email` WHERE `email` = '[email protected]' AND `a`.`status` = '1'
Filename: F:\wamp\www\project\system\database\DB_driver.php
Line Number: 331
您好,此代碼不能正常工作,$ _ GET是正常工作,我認爲這代碼創建一個問題,生病添加錯誤信息在我的問題你可以chack ... $ array = array('email'=> $ row ['email'],'a.status'=>'1'); $ query1 = $ this-> db-> select('a.id,title,a.status,description,image,a.email,tags,postdate,firstname,lastname,rc') - > join('users u ','u.email = a.email','left') - > where($ array) - > get('articles a'); –
鑑於此錯誤顯示:在 'where子句' 1054 未知列 '0' SELECT'a'.'id','title','a'.'status:數據庫出錯 錯誤編號''''描述','圖像','''''電子郵件','標籤','postdate','firstname','姓','rc'從('articles' a)LEFT JOIN'users'u ON'u'.'email' ='a'.'email' WHERE'0' ='email'AND'1' ='[email protected]'AND'a'.'status' ='1' 文件名:F:\ wamp \ www \ project \ system \ database \ DB_driver.php 行號碼:331 –
基本上'$ _GET ['rc']'和'$ this-> input-> get('rc') '是一樣的。它只是CI做事的方式。 '('email',$ row ['email'],'a.status'=>'1')'有'逗號'且應該'=>' –