model_name->call_head();foreach($headeras$item){ $name =$item['name']; $array['name']=$name; $array[&#"/> model_name->call_head();foreach($headeras$item){ $name =$item['name']; $array['name']=$name; $array[&#">

Home  >  Article  >  Backend Development  >  Calling stored procedure inside foreach loop in Codeigniter

Calling stored procedure inside foreach loop in Codeigniter

WBOY
WBOYforward
2023-09-17 19:25:03757browse

在Codeigniter中的foreach循环内调用存储过程

The code inside "Model" and "Controller" needs to be changed to include the code as shown below -

Inside "Controller"

$header = $this->model_name->call_head();
foreach($header as $item) {
   $name = $item['name'];
   $array['name'] = $name;
   $array['data'] = $item['data'];
   $child_val = $this->model_name->call_child($name);
   foreach($child_val as $value) {
      $array['child'] = array(
         'child_name' => $value['child_name'],
         'child_data' => $value['child_data']
      );
   }
}

Inside the 'model'

Translated into Chinese:

Inside the 'model'

public function call_head() {
   $query = "CALL PROCEDURE_HEAD()";
   $result = $this->db->query($query)->result_array();
   $query->next_result();
   $query->free_result();
   return $result;
}
public function call_child($name) {
   $query = "CALL PROCEDURE_CHILD($name)";
   $result = $this->db->query($query)->result_array();
   $query->next_result();
   $query->free_result();
   return $result;
}

The above is the detailed content of Calling stored procedure inside foreach loop in Codeigniter. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete