Welcome Guest, Not a member yet? Register   Sign In
Join multi other table
#1

[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
#2

[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.
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB