PHP CodeIgniter для l oop с insert_id - PullRequest
       1

PHP CodeIgniter для l oop с insert_id

0 голосов
/ 03 февраля 2020

У меня есть 2 таблицы. Я хочу добавить bndid к массиву данных в l oop для 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';

          }



    }
}

1 Ответ

0 голосов
/ 03 февраля 2020
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));

}}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...