1 回答

TA貢獻1797條經驗 獲得超6個贊
您正在使用result()函數來獲取記錄,但這會將記錄作為對象而不是數組。如果要獲取數組,則必須使用result_array()。
function userList() {
$data['userlist'] = $this->Useraccount_mod->getUser_list();
$this->load->view('Useraccount/Userlist', $data);
}
方法一:
function getUser_list() {
$query = $this->db->query("select * from users")->result_array(); //here we can use result() as well but it gives object not array
return $query;
}
<tbody>
<?php
if ($userlist > 0) {
foreach ($userlist as $row) {
?>
<tr>
<td width="100"><?php echo $row['username']; ?></td>
<td width="100"><?php echo $row['name']; ?></td>
<td width="100"><?php echo $row['address']; ?></td>
<td width="100"><?php echo $row['creatdate']; ?></td>
<td width="100"><?php echo $row['updateddate']; ?></td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="3" align="center"><strong>No Record Found</strong></td>
</tr>
<?php
}
?>
</tbody>
方法二:
function getUser_list() {
$query = $this->db->query("select * from users")->result();
return $query;
}
<tbody>
<?php
if ($userlist > 0) {
foreach ($userlist as $row) {
?>
<tr>
<td width="100"><?php echo $row->username; ?></td>
<td width="100"><?php echo $row->name; ?></td>
<td width="100"><?php echo $row->address; ?></td>
<td width="100"><?php echo $row->creatdate; ?></td>
<td width="100"><?php echo $row->updateddate; ?></td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="3" align="center"><strong>No Record Found</strong></td>
</tr>
<?php
}
?>
</tbody>
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報