PHP CodeIgniter for loop with insert_id



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

} }

相关内容

  • 没有找到相关文章

最新更新