我不明白为什么这没有将数据库值放在页面上。你能告诉我这段代码我做错了什么吗?我是 CodeIgniter 的新手,这是我第一次尝试将数组从模型传递到控制器以进行查看。
控制器代码:
public function showuser(){
$id = $this->uri->segment(3);
$this->load->model('user_model');
$data['user']= $this->user_model->view_user($id);
$this->load->view('include/header');
$this->load->view('user_view',$data);
$this->load->view('include/footer');
}
型号代码:
public function view_user($id){
$this->db->where('userid', $id);
$query = $this->db->get('users');
return $query->result();
}
查看代码:
<table width="300" border="0" cellpadding="2">
<tr>
<td width="143">First Name</td>
<td width="143"><?php echo $data['user']->firstname; ?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?php echo $data->lastname; ?></td>
</tr>
<tr>
<td>Company</td>
<td><?php echo $data->company; ?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo $data->email; ?></td>
</tr>
<tr>
<td>Phone</td>
<td><?php echo $data->phone; ?></td>
</tr>
<tr>
<td><p>Fax</p></td>
<td><?php echo $data->fax; ?></td>
</tr>
<tr>
<td>Address 1</td>
<td><?php echo $data->address1; ?></td>
</tr>
<tr>
<td><p>Address 2</p></td>
<td><?php echo $data->address2; ?></td>
</tr>
<tr>
<td>Address 3</td>
<td><?php echo $data->address3; ?></td>
</tr>
<tr>
<td>City</td>
<td><?php echo $data->city; ?></td>
</tr>
<tr>
<td>State/Region/Province</td>
<td><?php echo $data->state; ?></td>
</tr>
<tr>
<td>Postal Code</td>
<td><?php echo $data->zipcode; ?></td>
</tr>
<tr>
<td>Username</td>
<td><?php echo $data->username; ?></td>
</tr>
<tr>
<td>Account Type</td>
<td><?php echo $data->usertype; ?></td>
</tr>
</table>