I want to run a select query using db_query. Here is the code:
$nid_array = array(24,34,56,7,8);
$list_of_nids = implode(',',$nid_array);
$query = " SELECT *
FROM {table_name} as t
WHERE t.nid IN (:list_of_nids)";
$placeholders = array();
$placeholders[':list_of_nids'] = $list_of_nids;
$result = db_query($query, $placeholders)->fetchAll();
This query does not return any results.
Although if I do not use placeholders & replace :list_of_nids
with $list_of_nids
, then I get proper results.
I believe that when using placeholders the value of :list_of_nids
is taken as the $list_of_nids wrapped with single quote, which is causing problem here.
I want to use placeholders. So, how can use it without wrapping the value with single quotes.