My Codeigniter join query is not work. In a function just try to match RC code in users table and get email, this function is properly work, next target is match email id from article table and get article its work properly, but ill try to join the users table and article table beacause i need to get the users firstname & lastname from users table, I don't know is that right way or not, check my code below. Controller Part :
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 {
}
}
My Model :
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;}
}
check my code and tell me my mistakes Thanks in advance.
Error Shoe in View :
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