【问题标题】:Conditional fetching data from a table有条件地从表中获取数据
【发布时间】:2017-04-09 19:53:13
【问题描述】:

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

我有 3 张桌子:

“cursadas”包括:(id,user_id[是表“usuarios”的列“id”的外键],subject_id[是表“id”列的外键”材料”]、等级、日期)

“usuarios”包括:(id、用户名、姓名、姓氏、密码、类型、状态、日期)

“材料”包括:(id, career_id, name, description, hours)

这是“usuarios”表:

所以,当我编写一个简单用户(类型和状态 = 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; 
            }

【问题讨论】:

    标签: php codeigniter fetch


    【解决方案1】:

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

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

    查看此链接了解更多信息:

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

    【讨论】:

    猜你喜欢
    • 2016-04-05
    • 2019-06-02
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    相关资源
    最近更新 更多