2017-10-04 29 views
-1

你好傢伙我正在codeigniter框架上進行應用,我試圖迴應特定用戶的用戶信息,但它並不真正起作用。這個名字沒有被迴應。還有我的數據庫中用戶的所有電子郵件都被回顯。呼應在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); 
} 

所以基本上在視圖文件,我只W¯¯螞蟻1電子郵件正在呼應1特定用戶使用user_id而不是所有的用戶電子郵件,我也希望看到沒有被回顯的視圖頁面上的名稱和它的空白鏈接。名稱= voornaam

+0

你試圖讓多個用戶的相關信息以列表? – user4419336

+0

user_id – JohnDoe122

+0

不僅有1位用戶可能重複[用戶名未回顯](https://stackoverflow.com/questions/46545629/user-name-is-not-being-echoed) – DFriend

回答

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 } ?> 

或者獲得單人使用R數據

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> 
+0

控制器功能應該是命名爲userdetails而不是索引權? – JohnDoe122

+0

將它命名爲你所需要的任何一個 – user4419336

+0

鏈接現在不再工作了 – JohnDoe122