Calling stored procedure inside foreach loop in Codeigniter

WBOY
Release: 2023-09-17 19:26:02
forward
778 people have browsed it

在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']
      );
   }
}
Copy after login

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;
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!