gpt4 book ai didi

mysql - PHP CodeIgniter for 循环与 insert_id

转载 作者:行者123 更新时间:2023-11-29 15:11:22 26 4
gpt4 key购买 nike

我有 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';

}



}
}

最佳答案

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));

}}

关于mysql - PHP CodeIgniter for 循环与 insert_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60033178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com