CodeIgniter Forums
Join multi other table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Join multi other table (/showthread.php?tid=42141)



Join multi other table - El Forum - 05-27-2011

[eluser]haily_php[/eluser]
I have 4 table in database, now, I want to select all data from those 4 table. And my code:
Code:
$this->db->select("*");
  $this->db->join("tableB", "tableB.ID_B=product.ID_B');

  $this->db->join("DetailBill","DetailBill.ID_SP=product.idthanhvien");
  
  return $data=$this->db->get("product")->result_array();

And, result is an array that I want (because "Table B" table and "Detail Bill" table relate to "Product" table, but I want to take data from one more table (Table A). Table A only relate to Table B
Code:
$this->db->select("*");
  
  $this->db->join("tableA", "tableA.ID_A=tableB.ID_A');  

  $this->db->join("tableB", "tableB.ID_B=product.ID_B');

  $this->db->join("DetailBill","DetailBill.ID_SP=product.idthanhvien");
  
  return $data=$this->db->get("product")->result_array();

I don't know what do I do to join "Table A" to take data.


Sorry, my english is not well


Join multi other table - El Forum - 05-27-2011

[eluser]gigas10[/eluser]
Like this maybe?
Code:
$this->db->select("A.*, B.*, P.*, D.*");
$this->db->from("tableA AS A");
$this->db->join("tableB AS B", "B.ID_A=A.ID_A");  
$this->db->join("Product AS P", "B.ID_B=P.ID_B");
$this->db->join("DetailBill AS D","D.ID_SP=P.ID_SP");
$qry = $this->db->get();
return $qry->result();

Please make sure your quotes are consistent either between single quotes or double quotes while surrounding method parameters.


Join multi other table - El Forum - 08-15-2011

[eluser]Unknown[/eluser]
thans... :-)