【发布时间】:2017-04-10 13:47:22
【问题描述】:
我的登录系统正常工作,如果写入的用户名和密码对应于 ADMIN 或简单用户,它会打开一个不同的页面。
所有用户都存储在“usuarios”表中。
“usuarios”包括:(id、用户名、姓名、姓氏、密码、类型、状态、日期)。
当我以管理员身份进入系统时,程序必须显示一个表,其中所有“简单”用户都存储在“usuarios”表中。
我不知道如何进行查询:/。
这是我的代码:
我的视图文件(“user_view”):
<div id="body">
<table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
<thead>
<th>id</th>
<th>User</th>
<th>Name</th>
<th>Lastname</th>
<th>Password</th>
<th>Type</th>
<th>Status</th>
<th>Date</th>
</thead>
<tbody>
<?php
if ($records) { echo "<tr> <td>".$records['id']."</td> <td>".$records['username']."</td> <td>".$records['name']."</td> <td>".$records['lastname']."</td> <td>".$records['password']."</td> <td>".$records['type']."</td> <td>".$records['status']."</td> <td>".$records['date']."</td> </tr>"; }
?>
</tbody>
</body>
</html>
我的控制器文件:
public function info_usuarios(){
$data['records']=$this->m_login->getINFOUSER();
$this->load->view('user_view',$data);
print_r($data);
}
模型函数(该函数只显示登录用户的数据)
public function getINFOUSER(){
$query = $this->db->get_where('usuarios', array('id' => $this->session->userdata('id')));
if ($query->num_rows() > 0 ) {
return $query->row_array();
}
【问题讨论】:
-
如果你想显示所有用户,你不应该在 where 子句中使用会话,因为它总是会从你的数据库中返回一个唯一的行。相反,您可以使用您的状态字段。
-
@heliosk 但是伙计,我不明白。如何显示所有“用户”行(不是 ADMIN 行)?
-
@pradeep 看看朋友:S
-
您使用哪一列来声明用户是管理员还是普通用户?
-
@heliosk "type"=0 is an ADMIN "type"= 1 simpe user
标签: php codeigniter fetch