问题描述
大家好,我正在codeigniter框架上开发应用程序,我正在尝试回显特定用户的用户信息,但实际上并不能正常工作。名称未回显。
Hello guys I'm making application on the codeigniter framework and I'm trying to echo user info of a specific user but its not really working. The name is not being echoed. Also all the emails of the users in my database are being echoed.
(指向正确的tuser配置文件的链接虽然有效,但是链接的名称无效。
这是我的视图文件:
( The link to the right tuser profile works though but the name of the link doesn't. Its a blank link.This is my view file:
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);
}
所以基本上在视图文件上,我只希望1个电子邮件被回显为1使用user_id而不是所有用户电子邮件的特定用户,我也想在视图页面上看到未回显的名称及其空白链接。名称= voornaam
So basically on the view file, I only want 1 email being echoed of 1 specific user with using the user_id and not all the user emails, also I want to see the name on the view page which is not being echoed and its a blank link. name = voornaam
推荐答案
尝试这样
模型函数
// 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>
这篇关于回显用户信息在Codeigniter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!