Hello,
I'm just new to drupal 7, so I'm not sure if what I'm trying to do is right

I'm trying to pass delimited string in condition but I'm getting back this message

DOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 2: SELECT c.* FROM {city} c WHERE (id IN ()) ; Array ( )

here is my code

$cities_id="1,3";
$result= db_select("city","c")
            ->fields("c")
            ->condition("id", $cities_id,"in")
            ->execute();

Comments

Heine’s picture

For IN and BETWEEN, value must be an array:

$cities_id = array(1, 3);
$result = db_select("city","c")
            ->fields("c")
            ->condition("id", $cities_id, "IN")
            ->execute();
lamis.b’s picture

Thanks alot works like charm. I'm not sure why its not documented like this

Heine’s picture