Passing values from EntityFieldQuery to db_select Checked for this, but don't seem to be any specific answers to this question.

I'm trying to pass results from EntityFieldQuery to a db_select query, via a string. However, although debugging both queries with set values shows that they are operating correctly and providing the desired results, when using the string in db_select I am getting null results.

The purpose is to get certain node ID's as an integer value and pass them as an array of Entity_ID integer values, so the db_select function only selects table rows which match a certain Entity_ID.

I presume I'm making a output format error for the EntityFieldQuery, but can't work out what exactly it is.  Code is as follows:

// EntityFieldQuery
$query = new EntityFieldQuery();
$entities = $query-&gt;entityCondition('entity_type', 'node')
                   -&gt;entityCondition('bundle', 'contenttype1')
                   -&gt;propertyCondition('status', 1)
                    -&gt;fieldCondition('field_field', 'value', $contenttype2, '=')
                   -&gt;fieldOrderBy('field_field', 'value', 'ASC')
                    -&gt;execute();

// Debugging functions only, return correct values when tested
$show = array_keys($entities['node']);
echo 'this is show: ' . $show;

$print = var_dump($show);
echo 'this is print: ' . $print;

// db_select function, returns correct sum when '$entities' is replaced with integer value for entity_id
$dbquery = db_select('tablename', 't')
  -&gt;condition('t.entity_id', '$entities', '=');
$dbquery-&gt;addExpression('SUM(value)', 'value');

$result = $dbquery-&gt;execute()-&gt;fetchField();

// Debugging function only
print 'this is result: ' . $result;


The EntityFieldQuery is producing the correct values, but it isn't clear that they are in the correct format. The $print output is:

array(2) { [0]=&gt;int(213) [1]=&gt;int(214) }


At present, the SUM result works correctly when I replace '$entities' in the db_select with (e.g.) '213', but returns 0.0 when I use '$entities'.

EDIT: using 

dpq($dbquery); 
dpr($result);


Gives the confirm message:

SELECT SUM(value) AS value
FROM 
{votingapi_vote} v
WHERE  (v.entity_id = ) 


And the error message:

Warning: PDO::quote() expects parameter 1 to be string, array given in dpq() (line 1835 of /var/www/html/sites/all/modules/devel/devel.module).


What is the output format code / function I should be using for EntityFieldQuery?
Try this approach. after getting your entities using EntityFieldQuery, create a for loop in order to check the val that was stored in your variable $entities. Then use dsm or dpm to check if it returns a result. 

$results = '';
for ($i=0; $i &lt; count($your_entity) ; $i++) { 
    $query = db_select('yourtablename', 't');
    $query-&gt;fields('t');
    $query-&gt;condition('t.entity_id', $your_variable);
    $results = $query-&gt;execute()-&gt;fetchAll();
}
dsm($results);


Hope this helps you.