从表中有条件地获取数据 [英] Conditional fetching data from a table
问题描述
如果输入的用户名和密码对应于简单用户或管理员,我的登录系统将打开一个不同的窗口。
我有3个表:
cursadas包括:(id,user_id [是表 usuarios的列 id的外键],subject_id [是表 materias的列 id的外键。 ],年级,日期)
usuarios包括:(ID,用户名,名称,姓氏,密码,类型,状态,日期)
材料包括:(编号,职业编号,姓名,描述,工作时间)
这是表 usuarios: p>
因此,当我编写一个简单用户(类型和状态= 1)时出现仅针对简单用户的页面:
所以,这是我对程序的新目标:
不知道如何执行查询:S
这是我的用户信息中心( info_user):
< table class = 表格表格悬停 align =中心。 border = 1 cellspacing = 0 cellpadding = 0宽度= 700 id = tabla_busqueda
< thead>
< id< / th>
<用户< / th>
< th>名称// th;
< thastname< / th>
日期/日期
< / thead>
< tbody>
<?php
if(count($ records)> 0&& $ records!= false){
$ id = 1;
foreach($ records作为$ 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>
我的控制器功能:
公共函数info_user(){
$ data ['records'] = $ this-> m_login-> getINFO();
$ this-> load-&view;'info_user',$ data);
}
,模型函数 getInfo (不知道如何执行查询):
公共函数getINFO()
{
$ st = $ this-> db-> SELECT()
-> join()
-> join()
-> WHERE()
-> get()-> result_array();
返回$ st;
}
在您的模型中添加此方法:
公共函数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
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;
}
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
这篇关于从表中有条件地获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!