db_smartone = $this->load->database('onedev'); } function generate() { // truncate $this->db_smartone->query("TRUNCATE"); $parents = $this->db_smartone->select("DISTINCT(Nat_RelationParentID) parentid", false) ->join('nat_test', 'Nat_RelationParentID = Nat_TestID') ->where("Nat_RelationIsActive", "Y") ->order_by('Nat_TestSequence') ->get('nat_relation') ->result_array(); foreach ($parents as $k => $v) { // INSERT top parent $this->db_smartone->query(""); $parent_1 = $this->db_smartone->select() ->join('nat_test', 'Nat_RelationParentID = Nat_TestID') ->where('Nat_RelationParentID', $v['parentid']) ->where('Nat_RelationIsActive', "Y") ->order_by('Nat_TestSequence') ->get('nat_relation') ->result_array(); } } } ?>