尝试更新 2 个表中的数据

这是代码:


  if ($param1 == 'do_update') {

            $data['student_id']         = $this->input->post('student_id');

            $data['title']              = html_escape($this->input->post('title'));

            if ($this->input->post('description') != null) {

                $data['description']        = html_escape($this->input->post('description'));

            }


            $data['amount']             = html_escape($this->input->post('amount'));

            $data['amount_paid']        = html_escape($this->input->post('amount_paid'));

            $data2['amount']            = html_escape($this->input->post('amount'));


            /*$data['status']             = $this->input->post('status');*/

            $data['creation_timestamp'] = strtotime($this->input->post('date'));


            $this->db->where('invoice_id', $param2);

            $this->db->update('invoice', $data);

            $this->db->where('invoice_id', $param2);

            $this->db->update('payment', $data2);

2 表发票和付款...我可以使用特定 ID 更新“发票表”中的数据,但同时,它正在更新“付款表”中的整个列而不是该特定 ID。我可以看出在最后 4 行中做错了什么。

$data 字段属于 Invoice 表,$data2 字段属于 Payment 表


Invoice_id 在两个表中都很常见..


江户川乱折腾
浏览 111回答 1
1回答

人到中年有点甜

你实际上并没有使用你的 where 条件。尝试:$this->db->where('invoice_id', $param2)->update('invoice', $data); $this->db->where('invoice_id', $param2)->update('payment', $data2);
打开App,查看更多内容
随时随地看视频慕课网APP