从 table 中有条件地获取数据

Conditional fetching data from a table

如果写入的用户名和密码对应于简单用户或管理员,我的登录系统会打开一个不同的window。

我得到了 3 个 tables:

"cursadas" includes:(id, user_id[is the foreign key to the column "id" of the table "usuarios"], subject_id[is the foreign key to the column "id" of the table "materias"], grade, date)

"usuarios" includes:(id,username,name,lastname,password,type,status,date)

"materias" includes:(id, career_id, name, description, hours)

这是table“习惯”:

所以,当我写一个简单的用户(type & status = 1)时,会出现一个仅供简单用户使用的页面:

所以,这是我计划的新目标:

不知道怎么查询:S

这是我的用户仪表板 ("info_user"):

                <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>Date</th>
                </thead>


<tbody>
<?php

if (count($records) > 0 && $records != false) {
    $id = 1;
    foreach($records as $record) {

        echo "<tr>
                  <td>".$id."</td>
                  <td>".$record['username']."</td>
                  <td>".$record['name']."</td>
                  <td>".$record['lastname']."</td>
                  <td>".$record['date']."</td>
              </tr>";
       $id++;
    }

   }
?>
 
</tbody>

</body>
</html>

我的控制器功能:

        public function info_user(){

            $data['records']=$this->m_login->getINFO();
            $this->load->view('info_user',$data);
        }

和模型函数“getInfo”(不知道查询怎么做):

            public function getINFO()
            {
               $st = $this->db->SELECT()
                ->join()
                ->join()
                ->WHERE()
                ->get()->result_array();
            return $st; 
            }

在您的模型中添加此方法:

    public function getINFO(){

    $query = $this->db->get_where('usuarios', array('id' => $this->session->userdata('id')));
    if ($query->num_rows() > 0 ) {
        return $query->row_array();
    }
}

查看此 link 了解更多信息:

https://www.codeigniter.com/user_guide/database/results.html#result-arrays