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 关注
- 94 浏览
添加回答
举报