我需要使用join将数据库值放入我的文本框中

时间:2015-01-31 08:52:26

标签: database codeigniter join textbox

我的观点

<?php foreach ($single as $admin): ?>

                    <table class="table">
                    <tbody>                   

                        <div class="form-group margin_bot_20 " >
                        <div class="col-sm-2">Name of Company</div>
                        <div class="col-sm-10"> 
                            <input type="text" placeholder="Name of Company"     class="form-control txtbx-height" id="compneyname" value="<?php echo $admin->user_id; ?>" name="compneyname"  data-parsley-trigger="change"  data-parsley-required-message="Builder Name is required." s>                           

                        </div>

                      <?php endforeach; ?>

我的模特

public function update_admin($data){
            $this->db->select('*');
            $this->db->from('tbl_user');
            $this->db->where('user_id', $data);
            $query = $this->db->get();
            $result = $query->result();
            return $result;
           }   

我的控制器

$this->user->update_admin($user_id);
            $data['single'] = $this->user->update_admin($user_id);
            $this->load->view('edit_user', $data);
            $this->input->post('user_id');
            $this->layout->view_render("admin/user/edit_user", $data);

            $data = array(
            'companyname' => $this->input->post('compnayname'),
            'name' => $this->input->post('name'),
            );

我需要从tbl_user和tbl_userinfo这两个不同的表中获取值,并将它们显示在文本框中,显示我可以编辑它。

1 个答案:

答案 0 :(得分:0)

试试这个:

$this->db->select('*');
                $this->db->from('tbl_user');
                $this->db->join('tbl_userinfo', 'tbl_user.user_id = tbl_userinfo.user_id');
                $this->db->where('tbl_user.user_id', $data);
                $query = $this->db->get();
                $result = $query->result();
                return $result;