Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By lamis.b on
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
For IN and BETWEEN, value
For IN and BETWEEN, value must be an array:
Thanks alot works like charm.
Thanks alot works like charm. I'm not sure why its not documented like this
It is, see
It is, see http://drupal.org/node/310086