我不明白爲什麼這不會將數據庫值放在頁面上。你能告訴我我在做什麼這個代碼錯了嗎?我是CodeIgniter的新手,這是我第一次嘗試將數組從模型傳遞給控制器來查看。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>
這樣做!謝謝你的幫助! – jfur7 2013-05-01 07:44:14