【问题标题】:Fetching data, conditional table codeigniter获取数据,条件表codeigniter
【发布时间】: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


【解决方案1】:

这个很简单,你做一个简单的查询就可以找到type = 1的所有用户

SELECT * FROM usuarios WHERE type=1;

就是这样。

您可以使用 CodeIgniter 的方式进行编码。

$result = $this->db->get_where('usuarios', array('type =' => 1))->result();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
  • 2020-09-24
相关资源
最近更新 更多