我正在使用 MYSQL/Codeigniter。如果传递的值为空,MySQL 查询如何忽略条件,例如以下示例:
function get_category($category_id = 0){
return $this->db->query("SELECT * FROM {$this->table} c
INNER JOIN db_category_event ce
ON ce.category_id = c.category_id
INNER JOIN db_event_type e
ON e.event_id = ce.event_id
WHERE c.category_id = {$category_id}
WHERE c.visible = 1 AND e.visible = 1")
->result();
}