consulta de join en codeigniter

Estoy usando la function de unión en codeigniter y no puedo hacer que funcione. Solo muestra una tabla de datos pero la otra no es nueva. Codeigniter no puede entender esto. Alguien me ayuda a TNT por adelantado.

ver

<?php foreach ($query as $row): ?> <?php echo $row->answerA;?><br> <?php echo $row->answerB;?><br> <?php echo $row->answerC;?><br> <?php echo $row->comment;?><br> <?php echo $row->name; ?> <?php endforeach; ?> 

controller

  function getall(){ $this->load->model('result_model'); $data['query'] = $this->result_model->result_getall(); // print_r($data['query']); // die(); $this->load->view('result_view', $data); } 

model

  function result_getall(){ $this->db->select('tblanswers.*,cnetworkingentials.*'); $this->db->from('tblanswers'); $this->db->join('cnetworkingentials', 'tblanswers.answerid = cnetworkingentials.cid', 'right outer'); $query = $this->db->get(); return $query->result(); } 

EDITAR

este es el resultado de

 print_r($data['query']); die(); 

la matriz que devuelve:

 Array ( [0] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 83 [name] => Edvinas [second_name] => liutvaits [phone] => [email] => ledvinas@yahoo.ie ) [1] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 84 [name] => Edvinas [second_name] => liutvaits [phone] => [email] => ledvinas@yahoo.ie ) [2] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 85 [name] => Edvinas [second_name] => Liutvaitis [phone] => [email] => ledvinas@yahoo.ie ) [3] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 86 [name] => EdvinasQ [second_name] => LiutvaitisQ [phone] => 12345678 [email] => ledvinas@yahoo.ie ) [4] => stdClass Object ( [answerid] => [userid] => [questionid] => [answerA] => [answerB] => [answerC] => [comment] => [cid] => 87 [name] => Edvinas [second_name] => Liutvaitis [phone] => 123456 [email] => ledvinas@yahoo.ie ) ) 

estructura de la table

cartas cnetworkingenciales

cid (PRIMARIO), nombre, segundo nombre, teléfono, correo electrónico

tblanswers

answerid (PRIMARY), ID de usuario, questionid, answerA, answerB, answerC.

Prueba con esto:

 $this->db->join('cnetworkingentials', 'tblanswers.answerid = cnetworkingentials.cid'); 

O

 $this->db->join('cnetworkingentials', 'tblanswers.answerid = cnetworkingentials.cid', 'inner'); 

E imprime el resultado para ver si es lo que quieres

Quite la label select (), ya que necesita todos los términos.

U puede modificar código como

 $this->db->join('cnetworkingentials', 'tblanswers.answerid = cnetworkingentials.cid', 'outer'); $query = $this->db->get('tblanswers'); return $query->result(); 

Si sus dos tablas están relacionadas, entonces debería funcionar. ¿Por qué estás usando la combinación externa derecha? Simplemente use Inner Join o cualquier otra combinación y funcionará. Por favor, lea acerca de los diferentes types de JOIN aquí http://www.w3schools.com/sql/sql_join.asp y aquí http://dev.mysql.com/doc/refman/5.0/en/join.html

Espero que esto ayude

Gracias

¿Cuál es la tabla principal que desea consultar? Bueno, puedes probar este, sugirió que cuando uses uniones, debes especificar un alias para cada tabla:

  function result_getall(){ // if you want to query your primary data from the table 'tblanswers', $this->db->select('a.*,b.*'); <-- select what you might want to select $this->db->from('tblanswers a'); $this->db->join('cnetworkingentials b', 'b.cid = a.answerid', 'left'); $query = $this->db->get(); return $query->result(); // if you want to query your primary data from the table 'cnetworkingentials', $this->db->select('a.*,b.*'); <-- select what you might want to select $this->db->from('cnetworkingentials a'); $this->db->join('tblanswers b', 'b.answerid = a.cid', 'left'); $query = $this->db->get(); return $query->result(); }