I am trying to query my database using the codeigniter active write class. I have several blog posts stored in a table. The query is for a search function that pulls out all messages that have specific categories assigned to them. Thus, the column “category” of the table will have a list of all categories for this message in a certain order, separated by commas, for example: “Politics, history, sociology”, etc.
If the user selects, say, a policy and history, the names of all posts that have BOTH these categories should be returned.
Correctly? Thus, the list of requested categories will be an array of $ cats. I thought it would work -
foreach ($cats as $cat){
$this->db->like('categories',$cat);
}
Having produced it -
$ this-> db-> like ('categories', 'policy'); $ This-> db-> how ('categories', 'History');
(which would create the "WHERE categories LIKE"% Politics% 'and the LIKE categories'% History%')
But this will not work, it seems, only produces the first statement. The problem, I think, is that the column name is the same for each of the chained queries. There is nothing in the CI user guide (http://codeigniter.com/user_guide/database/active_record.html) as they seem to assume that each associated statement will be for a different column name, Does anyone know how I can do this to do?
Thank!
edit. , , . ""...