Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created December 1, 2010 16:55
Show Gist options
  • Save gavinblair/723791 to your computer and use it in GitHub Desktop.
Save gavinblair/723791 to your computer and use it in GitHub Desktop.
<?php
//updated to fit http://drupal.org/writing-secure-code
function ajax_autocomplete(){
$q = $_GET['z'].'%';
$limit = intval($_GET['limit']);
$sql = "select distinct title from node where status = 1 AND (type = 'product' OR type = 'model_documentation') AND title LIKE '%s' order by title limit %d";
$result = db_query($sql, $q, $limit);
while($row = db_fetch_array($result)) {
echo "{$row['title']}\n";
}
exit();
}
@gavinblair
Copy link
Author

Nice. Gave it a shot, worked but I had to change %s to '%s'

Your version fits better with http://drupal.org/writing-secure-code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment