Convert query to D7 for db_query_range How do I convert the query below properly to 7x?

$query = db_query('SELECT latitude, longitude FROM {zipcodes} WHERE city = UPPER("%s") LIMIT 1', $search_term);




$query = db_query('SELECT latitude, longitude FROM {zipcodes} WHERE zip = "%s" LIMIT 1', $search_term);


The Coder module advised that I change it to db_query_range so I tried the code below.

$query = db_query_range('SELECT z.latitude, z.longitude FROM {zipcodes} z WHERE z.city = UPPER(:city)', 0, 1, array(':city' =&gt; $search_term);




$query = db_query_range('SELECT z.latitude, z.longitude FROM {zipcodes} z WHERE z.zip = :zip', 0, 1, array(':zip' =&gt; $search_term);
As far as I can tell your code is fine except for a small syntax error; you're missing a closing parenthesis on the end of the statement. It should be:

$query = db_query_range('SELECT z.latitude, z.longitude FROM {zipcodes} z WHERE z.city = UPPER(:city)', 0, 1, array(':city' =&gt;$search_term));


It's often handy to split the arguments out into a separate array so this sort of thing is easily avoidable:

$args = array(':city' =&gt; $search_term);
$query = db_query_range('SELECT z.latitude, z.longitude FROM {zipcodes} z WHERE z.city = UPPER(:city)', 0, 1, $args);