Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

php - Conditional fetching data from a table

My login system opens a different window if the username &password written correspond to a simple user or an ADMIN.

I got 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)

This is the table "usuarios":

enter image description here

So,when i write a simple user (type & status = 1) a page only for simple users appears:

So,this is my new goal to my program:

enter image description here

Do not know how to do the query :S

Here is my user dashboard ("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>

My controller function:

        public function info_user(){

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

And the model function "getInfo" (do not know how to do the query):

            public function getINFO()
            {
               $st = $this->db->SELECT()
                ->join()
                ->join()
                ->WHERE()
                ->get()->result_array();
            return $st; 
            }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Your model add this method:

    public function getINFO(){

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

See this link for more :

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...