Using SQL functions in conditionals in Drupal 7 db_select()
change

$query-&gt;addExpression("LOWER(ttd.name) = $category");


to

$query-&gt;where('LOWER(ttd.name) = :category', array(':category' =&gt; $category));