首页 文章

回显在Codeigniter中不起作用的用户信息

提问于
浏览
-1

大家好,我正在使用codeigniter框架进行应用程序,我正在尝试回显特定用户的用户信息,但它并没有真正起作用 . 这个名字没有得到回应 . 此外,我的数据库中的所有用户的电子邮件都被回显 .

(链接到正确的tuser配置文件但是链接的名称没有 . 它是一个空白链接 . 这是我的视图文件:

foreach($userdetail_list as $row): ?>
<tr>
    <td>
        <a href="<?php echo base_url() . 'User/userdetails/'.$row['user_id']?>">
          <?php echo $row['voornaam']; ?>
        </a>
    </td>
    <td>
        <?php echo $row['email'];?>
    </td>
</tr>
<?php endforeach;  ?>

我的模型文件:

function getdata($user_id){
  $this->db->select("*"); 
  $this->db->from('users');
  $this->db->where('user_id', $user_id);
  $query = $this->db->get();
  return $query->result();
 }

    public function getUserInfo($user_id) {
        $arrReturn = array();
        $this->db->select('*');
        $this->db->from('users');
        $this->db->where('user_id', $user_id);
        $query = $this->db->get();
        $result = $query->result_array();
        if (!empty($result)) {
            $arrReturn = $result[0];
        }
        return $arrReturn;
    }

我的控制器文件:

public function userdetails($user_id)
 {
  //load the User_model
  $this->load->model('User_model');

  //call function getdata in de Product_model
  $data['userdetail_list'] = $this->User_model->getdata($user_id);

  $data['user'] = $this->User_model->getUserInfo($user_id);

  //laad view
  $data['main_content'] = 'profiel_user';
  $data['main_content'] = 'details';
  $this->load->view('profiel_user',$data);
 }

所以基本上在视图文件上,我只想要使用user_id而不是所有用户电子邮件回复1个特定用户的1封电子邮件,我也希望在视图页面上看到未被回显的名称及其空白链接 . name = voornaam

1 回答

  • 1

    试试这样吧

    模型功能

    // Gets a list of multiple users.
    function getdata(){
        $query = $this->db->get('users');
        return $query->result_array();
    }
    
    // Gets the users information 
    public function getUserInfo($user_id) {
        $this->db->where('user_id', $user_id);
        $query = $this->db->get('users');
        return $query->row_array();
    }
    

    控制多个用户

    public function userdetails($user_id) {
    
        $this->load->model('user_model');
    
        $data['userdetail_list'] = $this->user_model->getdata();
    
        $this->load->view('profiel_user', $data);
    
    }
    

    查看多个用户列表

    <?php foreach($userdetail_list as $row){ ?>
        <tr>
            <td>
                <a href="<?php echo base_url('user/userdetails/'.$row['user_id']);?>">
                  <?php echo $row['voornaam']; ?>
                </a>
            </td>
            <td>
                <?php echo $row['email'];?>
            </td>
        </tr>
    <?php }  ?>
    

    或者获取单个用户数据

    public function userdetails($user_id) {
    
        $this->load->model('user_model');
    
        $user_info = $this->user_model->getUserInfo($user_id);
    
        $data['user_id'] = $user_info['user_id'];
    
        $data['username'] = $user_info['username'];
    
        $this->load->view('profiel_user', $data);
    
    }
    

    视图

    或者对于单个用户选项

    <a href="<?php echo base_url('user/userdetails/' . $user_id);?>"><?php echo $username;?></a>
    

相关问题