【发布时间】:2015-11-30 14:56:23
【问题描述】:
我的表单上有一个名为“status”的单选按钮,其值为 1 和 0。因此,当我提交表单并选中其中一个单选按钮时,它存储在数据库中。问题是当我从数据库中检索包含状态列名称的数据时,我希望将其设置为“活动”或“非活动”。
查看:
<table class="table table-condensed">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Status</th>
<th>Date Registered</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($users as $key => $value) {?>
<tr>
<td><?php echo $value['firstname']; ?></td>
<td><?php echo $value['lastname']; ?></td>
<td><?php echo $value['email']; ?></td>
<td><?php echo $value['status']; ?></td>
<td><?php echo $value['datereg']; ?></td>
<td>
<a href="<?php echo site_url('main/showUser/'.$value['id']); ?>">
<i class="material-icons" title="Click to update">mode_edit</i></a> |
<a href="" class="remove"><i class="material-icons" title="Click to remove">
delete</i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
控制器:
public function usersPage() {
$data['users'] = $this->user->getUsers();
$this->load->view('user_page' , $data);
}
型号:
public function getUsers() {
$this->db->select('id, email, first_name, last_name, date_registered, status');
$this->db->from('auth_users');
$query = $this->db->get();
$result = $query->result();
foreach ($result as $key => $value) {
$data[$key] = array(
'id' => $value->id,
'firstname' => $value->first_name,
'lastname' => $value->last_name,
'datereg' => $value->date_registered,
'email' => $value->email,
'status' => $value->status
);
}
return $data;
}
【问题讨论】:
标签: php mysql codeigniter