如果(status == 0)我只想这样做,那么只有在运行条件且打印只与status == 0 record相关时。当status == 1时,它会绕过where子句并打印两个数据状态0和1.我不知道如何为此构建查询。请帮助我。
我的型号代码
function listing(){
$admin_id = $this->session->userdata('admin_id');
$query = $this->db->select('student_info.*,admin.status')
->from('student_info')
->where('student_info.admin_id',$admin_id)
->join('admin','admin.admin_id = student_info.admin_id')
->get();
return $query->result();
}
此代码正常工作并打印状态为0或1的单独数据。
只有admin_id = 1包含Status = 1,其他id包含0状态。
答案 0 :(得分:0)
试试这个:
function listing(){
$admin_id = $this->session->userdata('admin_id');
$query = $this->db->select('student_info.*,admin.status')
->from('student_info')
->join('admin','admin.admin_id = student_info.admin_id')
->where("student_info.admin_id = IF (admin.status = 0, $admin_id, '>-1'")
->get();
return $query->result();
}
答案 1 :(得分:0)
使用以下代码替换您的功能...
public class ProfileRepositoryFactory : IProfileRepositoryFactory
{
public IProfileRepository Create(string profileType)
{
switch(profileType)
{
case "A":
return new DatabaseProfileRepository();
case "B":
return new XmlProfileRepository();
}
}
}
答案 2 :(得分:0)
它解决了我的问题..
function listing()
{
$admin_id = $this->session->userdata('admin_id');
$this->db->select('student_info.*,admin.status');
$this->db->from('student_info');
$this->db->join('admin','admin.admin_id = student_info.admin_id');
$this->db->where('student_info.admin_id',$admin_id);
$this->db->or_where('admin.status < 1');
$query = $this->db->get();
return $query->result();
}
答案 3 :(得分:0)
<?php
function listing($status)
{
if($status == 0){
$this->db->select('student_info.*,admin.status');
$this->db->from('student_info');
$this->db->where('student_info.admin_id',$admin_id);
$this->db->join('admin','admin.admin_id = student_info.admin_id');
$query = $this->db->get();
return $query->result();
}else{
$this->db->select('student_info.*,admin.status');
$this->db->from('student_info');
$this->db->join('admin','admin.admin_id = student_info.admin_id');
$query = $this->db->get();
return $query->result();
}
}
?>