PHP contextual filter code in drupal 7 'no query was run' I am using the contextual filter code in views to filter more options for the view, using this snippet:

$uid= $GLOBALS['user']-&gt;uid;

$result = db_query('SELECT users_node__field_data_field_agencyname.field_agencyname_nid as agencyid
FROM {field_data_field_agencyname} users_node__field_data_field_agencyname 
WHERE users_node__field_data_field_agencyname.entity_id=:uid AND users_node__field_data_field_agencyname.deleted=0 AND users_node__field_data_field_agencyname.entity_type=:user',array(':uid'=&gt;$uid,':user'=&gt;'user'));

return $result-&gt;agencyid;


but no query is run shows up on the sql pane ?

How come?
I would suspect that no query is run because your code snippet isn't returning anything. The thing that jumps out to me is that you are trying to use $result as the first row returned by the query, however it is actually the entire result set.  For example, retrieving data from a DB usually look similar to the code below:

$result = db_query($sql);

// Iterate over the collection ($result).
foreach ($result as $record) {
  $agency_id = $record-&gt;agencyid;
}


In the example you posted above, you could use the following code snippet to pull a single field from the first row in the result set:

// This would return the agency ID.
return db_query($sql)-&gt;fetchField();


Take a look at the documentation of fetchField() for more information on how it is used.