php - codeigniter join query issue in email -


my codeigniter join query not work. in function try match rc code in users table , email, function work, next target match email id article table , article work properly, ill try join users table , article table beacause need users firstname & lastname users table, don't know right way or not, check 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() $row) {                     $data[] = $row;                 }                 return $data;             }             else {return null;}         } else {return null;}      }  

check code , tell me mistakes in advance.

error shoe in view :

  database error occurred    error number: 1052    column 'email' in clause ambiguous    select `a`.`id`, `title`, `a`.`status`, `description`, `image`, `a`.`email`, `tags`, `postdate`, `firstname`, `lastname`, `rc` (`articles` a) left join `users` u on `u`.`email` = `a`.`email` `email` = 'admin@gmail.com' , `a`.`status` = '1'    filename: f:\wamp\www\project\system\database\db_driver.php    line number: 331 

refactored code. copy-paste , check working.

controller:

public function user_article() {         $rc = $this->input->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($rc);         $this->load->view('sd/header',$data);         $this->load->view('sd/user_article', $data);         $this->load->view('sd/footer', $data);     }      else      {      } } 

model:

function u_article($rc) {       $query = $this->db->select('email')->where('rc',$rc)->get('users');     $result = $query->result_array();      if ($query->num_rows() > 0)      {         $row = $query->row_array();          $array = array ('u.email' => $row['email'], 'a.status' => '1');          $query1 = $this->db->select('a.id,a.title,a.status,a.description,a.image,a.email,a.tags,a.postdate,u.firstname,u.lastname,u.rc')->join('users u','u.email = a.email','left')->where($array)->get('articles a');          if ($query1->num_rows() > 0)          {             foreach ($query1->result() $row)              {                 $data[] = $row;             }             return $data;         }         else {return null;}     } else {return null;} } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -