【问题标题】:PHP CodeIgniter for loop with insert_idPHP CodeIgniter for 带有 insert_id 的循环
【发布时间】:2020-02-03 04:41:01
【问题描述】:

我有 2 个表我想将 bndid 添加到循环中的数组数据中 bndid=insert_id

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Relatives_model extends CI_Model {


    public function save($relative_list){
        for ($x = 0;$x< count($relative_list);$x++){
          $dat[]=array(

            'bnddesc'=> $relative_list[$x]['bnddesc'],

            'bndprice'=> $relative_list[$x]['bndprice'],


            );

            $data[]=array(

              'no'=> $relative_list[$x]['no'],

              'qty'=> $relative_list[$x]['qty'],


              );


          }
          try{
          for($x=0;$x<count($relative_list);$x++){

            $this->db->insert('tbl_bnd',$dat[$x]);
            $this->db->insert('tbl_invbnd',$data[$x]);
            $insert_id = $this->db->insert_id();
            $q = $this->db->get_where('tbl_bnd', array('bndid' => $insert_id));
            return $q->row();


          }
          return 'success';
          }catch(Exception $e){
          return 'failed';

          }



    }
}

【问题讨论】:

    标签: mysql ajax codeigniter insert


    【解决方案1】:
    class Quview extends CI_Controller {
    public function index(){
        $this->load->helper(array('form', 'url'));
    
        $this->load->library('form_validation');
    
    
    
        $data['contents'] = 'admin/quview';
        $this->load->view('templates/index',$data);
    }
        public function save(){
        $relatives_list=$this->input->post('data_table');
        $this->load->model('relatives_model');
        $status = $this->relatives_model->save($relatives_list);
        $this->output->set_content_type('application/json');
        echo json_encode(array('status' => $status));
    

    } }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 2013-10-08
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多