• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to query dynamic self referencing hierarchy with active record

#1
[eluser]Unknown[/eluser]
i have function model like this

Quote:
$this->db->select_max("level");
$this->db->from("prod_category");
$query = $this->db->get();
foreach ($query->result() as $row)
{
$max = $row->level;
}
$fielselect = '';
if($max){
for($c=1;$c<=$max;$c++){
$arrayselect = 't'.$c.'.name as lev'.$c;
$fielselect = $fielselect.','.$arrayselect;
}
$fieldt = substr($fielselect, 1);
}
$this->db->select($fieldt);
$this->db->from('prod_category AS t1');
$this->db->join('prod_category AS t2','t2.parent = t1.id_category','left');
$this->db->join('prod_category AS t3','t3.parent = t2.id_category','left');
$this->db->join('prod_category AS t4','t4.parent = t3.id_category','left');

$this->db->where("t1.name",'Electronic');
$this->db->or_where("t1.name",'Cloth');
$this->db->or_where("t1.name",'Car');
$this->db->or_where("t1.name",'Property');


$hasil = $this->db->get();
if($hasil->num_rows() >0)
{
$data = $hasil->result();
}
$hasil->free_result();
return $data;

how can i change the red one to dynamic where query with active record query


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.