title: Using entity_id in a db_query in views_php (Drupal 7)
body: <p>I have created the following code in views_php:</p>
  
  <pre><code>$userseeking = db_query("SELECT field_seeking_tid FROM {field_data_field_seeking} WHERE entity_id = 6")-&gt;fetchAll(PDO::FETCH_ASSOC);
  $userseekingcount = count($userseeking);
  return $userseekingcount
  </code></pre>
  
  <p>In the above example, I use a specific value of '6' for entity_id. I receive the expected result from this query.</p>
  
  <p>However, the entity_id needs to be a variable dependent on the logged-in user's Profile ID (connected to their User ID).</p>
  
  <p>I therefore introduce 3 lines to retrieve the PID ($currentpid) from the current user. I have confirmed that these 3 lines return a $currentpid value of 6. When I ammend the db_query to select values where the entity_id = $currentpid, there appears to be a failure, although they should yield the same result - see code below:</p>
  
  <pre><code>global $user;
  $currentuser = $user-&gt;uid;
  $currentpid = db_query('SELECT pid FROM {profile} WHERE uid = ' . $currentuser . ' limit 1')-&gt;fetchField();
  
  $userseeking = db_query("SELECT field_seeking_tid FROM {field_data_field_seeking} WHERE entity_id = ' . $currentpid . '")-&gt;fetchAll(PDO::FETCH_ASSOC);
  $userseekingcount = count($userseeking);
  return $userseekingcount
  </code></pre>
  
  <p>Am I misusing how entity_id is referenced in this query?</p>
  
  <p>Thanks for your help!</p>
  
  <p>PS This may not be the cleanest code, so I apologise in advanced! :)</p>