I have a function that retrieves all tags from a table:
function global_popular_tags() { $this->db->select('tags.*, COUNT(tags.id) AS count'); $this->db->from('tags'); $this->db->join('tags_to_work', 'tags.id = tags_to_work.tag_id'); $this->db->group_by('tags.id'); $this->db->order_by('count', 'desc'); $query = $this->db->get()->result_array(); return $query; }
I have another table called "work". There is a βdraftβ column in the βworkβ table with values ββof 1 or 0. I want COUNT (tags.id) to take into account whether the work with a specific tag works in draft mode (1) or not.
Say that there are 10 works marked, for example, by βdesignβ. COUNT will be 10. But 2 of these parts of the job are in draft mode, so the COUNT value should really be 8. How do I do this?
sql php activerecord codeigniter
Jack
source share