db_query("SELECT title FROM {node} WHERE type IN('%s') AND title LIKE '%s%%' LIMIT 10", implode("','", $settings['node_types']), $string);
And the query string ends up being SELECT title FROM {node} WHERE type IN('page','story') AND title LIKE 'te%' LIMIT 10
And I have a couple of stories and pages called test1, test2, test3, test4
But no results are returned.
However when I only have just ('story') in the IN query part it returns results correctly
Just in case anyone is wondering this is for the node quick find module And here is the code
/**
* Autocomplete callback
*
* @param mixed $delta
* Provides the unqiue ID for the block provided by this module
* @param string $string
* The string to lookup
*/
function node_quick_find_autocomplete($delta = 0, $string = '') {
$settings = variable_get('node_quick_find_' . $delta, array());
$matches = array();
if ($string) {
$string = strtolower($string);
if (empty($settings['node_types'])) {
$result = db_query("SELECT title FROM {node} WHERE title LIKE '%s%%' LIMIT 10", $string);
}
else {
$result = db_query("SELECT title FROM {node} WHERE type IN('%s') AND title LIKE '%s%%' LIMIT 10", implode("','", $settings['node_types']), $string);
}
while ($node = db_fetch_object($result)) {
$matches[$node->title] = check_plain($node->title);
}
}
print drupal_to_js($matches);
exit();
}
Comments
Your IN statement turns into
Your IN statement turns into a string like this: IN('\'page\', \'story\'') which includes a single weird string.
You should declare an '%s' for each node type.
--
ufku.com - IMCE - BUEditor
Thank you very much. It
Thank you very much. It worked perfectly