用一次执行更新三个表 [英] updating three table with one execution

查看:99
本文介绍了用一次执行更新三个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试更新三个表与一个按钮执行,但为什么只是t_user更改? t_publisher和t_label没有更改,没有错误警告..

i try to updating three tables with one button execution, but why just t_user that changed? t_publisher and t_label didnt change and no error warning..

function update($id_user=null){

        if (($this->input->post('submit') == 'Update')){
            $user=$this->input->post('username');
            $pass=$this->input->post('userpassword');
            $ussta=$this->input->post('userstatus');
            $usty=$this->input->post('usertype');
            $id_label = $this->db->query("select ID_LABEL from t_label where LABEL = '$name->USER_NAME'")->row();
            $id_publisher = $this->db->query("select ID_PUBLISHER from t_publisher where PUBLISHER = '$name->USER_NAME'")->row();

        $data = array(
            'USER_NAME' => $user,
            'USER_PASS' => $pass,
            'USER_STATUS' => $ussta,
            'USER_TYPE' => $usty
            );

        $data2 = array(
            'LABEL' => $user,
            );

        $data3 = array(
            'PUBLISHER' => $user,
            );

        $this->db->where('USER_ID', $this->input->post('id'));
        $this->db->update('t_user', $data);
        $this->db->where('ID_LABEL', $this->input->post('$id_label'));
        $this->db->update('t_label', $data2);
        $this->db->where('ID_PUBLISHER', $this->input->post('$id_publisher'));
        $this->db->update('t_publisher', $data3);
        redirect("registrasi/reg");
        }
        $var['data'] = $this->db->query("select * from t_user where USER_ID= '$id_user'")->row_array();  
        $this->load->view('update', $var);
        }

请帮助:)

推荐答案

尝试

function update( $id_user = NULL ){
    if ( ( $this->input->post( 'submit' ) === 'Update' ) ) {
        $user = $this->input->post( 'username' );
        $pass = $this->input->post( 'userpassword' );
        $ussta = $this->input->post( 'userstatus' );
        $usty = $this->input->post( 'usertype' );

        $sql = "SELECT ID_LABEL FROM t_label WHERE LABEL = ?";
        $id_label = $this->db->query( $sql, array( $name->USER_NAME ) )->row();

        $sql = "SELECT ID_PUBLISHER FROM t_publisher WHERE PUBLISHER = ?";
        $id_publisher = $this->db->query( $sql, array( $name->USER_NAME ) )->row();

        $data = array(
            'USER_NAME' => $user,
            'USER_PASS' => $pass,
            'USER_STATUS' => $ussta,
            'USER_TYPE' => $usty
            );

        $data2 = array(
            'LABEL' => $user,
            );

        $data3 = array(
            'PUBLISHER' => $user,
            );

        $this->db->where('USER_ID', $this->input->post('id'));
        $this->db->update('t_user', $data);

        $this->db->where('ID_LABEL', $id_label);
        $this->db->update('t_label', $data2);

        $this->db->where('ID_PUBLISHER', $id_publisher);
        $this->db->update('t_publisher', $data3);

        redirect("registrasi/reg");
    }

    $var['data'] = $this->db->query( "SELECT * FROM t_user WHERE USER_ID= '$id_user'")->row_array();
    $this->load->view('update', $var);
}

我有点困惑。它是一个模型文件?如果是这样,为什么有一个 redirect 命令?还有为什么有一个 $ this-> load-> view()?再一次,$ name来自哪里?您可以将 $ id_user 指定为默认参数,您可以在此文件中使用它?

I'm a bit confused. Is it a model file? If it's so, why there is a redirect command? And also why there is a $this->load->view()? And once more, where $name came from? You assign $id_user as default parameter, where do you use it in this file?

这篇关于用一次执行更新三个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆