如何检查连接表中是否存在特定ID的列,并将结果存储在变量中?我在codeigniter中有这个模型,有d.* 几个结果,我需要添加一个额外的变量“response = 0或1”来从连接中获得。
function getAllActive($placeid = false, $response = false)
{
$query = $this->db->select("d.* ");
//QUESTION SECTION
if($reponse){
$query = $query->join($this->table_demand_menu.' dm', 'dm.fk_demand = d.id', 'left', FALSE);
$query = $query->where("dm.fk_demand", 'd.id');
**//WE JOIN WHERE ROWS WITH DEMAND IDs EXIST - ofc they will for many cases**
// QUESTION!!! BUT IF THE ROW HAS A COLUMN WITH PLACEID - used 'having' as example
$query = $query->having("dm.restaurant_id ==". $placeid);
//IF TRUE RETURN IT AS 1 IF FALSE RETURN IT AS 0 and spit it out in a variable AS reponse
}
$query = $query->group_by("d.id");
$query = $query->get($this->table_name.' d');
return $query->result();
}
1条答案
按热度按时间wztqucjr1#