If语句或如果特定ID存在于codeigniter的联接表列中

inb24sb2  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(103)

如何检查连接表中是否存在特定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();
}
wztqucjr

wztqucjr1#

if($response){
$query = $query->select("  (SELECT COUNT(*) FROM ".$this->table_demand_menu." dm WHERE dm.restaurant_id = ".$id." AND dm.fk_demand = d.id) AS response");
        }

相关问题