Search code examples
mysqlsqlexpressionengine

pipe charecters data in expression engine query as parameters


$query =  $this->EE->db->query("SELECT * FROM exp_categories WHERE parent_id=$parent_id order by cat_id ASC");

and $parent id = 4|7|5|6 (for category parent id passed from template by user)

now query should return result for both parent id's.

it's showing result only for the last parent id.


Solution

  • Not totally clear on what you are asking. I think you want your query to be:

    SELECT * 
    FROM exp_categories 
    WHERE parent_id 
    IN (4, 5, 6, 7) 
    ORDER BY cat_id ASC;
    

    If so you need to take $parent_id from piped-list (4|7|5|6) and transform it to a comma-separated list (4, 5, 6, 7).