问题
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":
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:
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;
}
回答1:
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
来源:https://stackoverflow.com/questions/43311205/conditional-fetching-data-from-a-table