jquery - 我想将 ids 从模型($data)返回到 Controller

标签 jquery mysql sql ajax codeigniter

enter image description here

在上图中,我选择要插入的 3 条记录,我想从模型到 Controller 获取这 3 条记录 id,我想在打印页面的 ajax 成功中访问这些记录

Controller :

public function createPaymentAllocation(){    

    $bilty_ids         = $this->input->post('due_ids');
    $biltyCount        = count($bilty_ids);

     $agent          = $this->input->post('agent');
     $due_to         = $this->input->post('due_to');

      for($i = 0; $i < $biltyCount; $i++){

      $data = array(
            'agent_id'            =>$agent,
            'pay_dueto'           =>$due_to,
            'mr_no'               =>$bilty_ids[$i],
             );

      $modelResult = $this->PayRecAllModel->inserPaymentAllocation($data);
      $this->PayRecAllModel->changeStatus($bilty_ids[$i]);
    }

      if(!empty($modelResult)){
         $data['PaymentRecAllocation'] = array(
                'form_status'     => 'true',
                'form_message'    => 'Payment Recovery  has been successfully Allocate'
                );

      }else{
            $data['PaymentRecAllocation'] = array(
                'form_status'     => 'false',
                'form_message'    => 'Something went wrong.'
            );
      }
      echo json_encode($data);
  } 

型号:

public function inserPaymentAllocation($data){
                 print_r($this->input->post());
                 exit();

                if($this->db->insert('payment_rec_allocn', $data)){       

                        return   true;

                 }else {
                        return  false;
                 }
          }

在模型中的 print_r 之后,它返回以下数组。

Array
(
    [agent] => 291
    [rec_type] => lr_no
    [due_ids] => Array
        (
            [0] => 7
            [1] => 8
            [2] => 9
        )

)

数据插入 Controller 后如何返回这 3 个 id

最佳答案

在代码中添加数组

$modelResult[] = $this->PayRecAllModel->inserPaymentAllocation($data);

关于jquery - 我想将 ids 从模型($data)返回到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57272796/

相关文章:

Javascript 在点击时更改整个 div

javascript - 如何从 Jqwidgets 中的嵌套行获取选定行数据

javascript - 如何比较两个 HTML 元素的渲染

MySQL 外键约束失败

mysql - 供远程 Excel 用户使用的数据库

javascript - 如何在移动设备上强制使用桌面 View - Bootstrap?

mysql - 省略前 5 行?

mysql - 我可以在 MySQL 中组合两个更新查询以使其更快吗?

sql - 如何重复 SQL 插入直到 pg-promise 成功?

mysql - 内部连接函数重复内容