2

I'm using Drupal 7 with the current mySQL version. I've got a custom profile field table that includes an entity_id (which corresponds to the user id) and a value field, which has one of a number of text strings that users can select as a personal interest. The number of strings a user can select for their profile is variable.

I need to query out the logged in user's list of interests, then query out any users who have any matching interests and their user id. I have a query/subquery script that basically works:

$subquery = db_select('table')                          
    ->fields('table', array('value'))
    ->condition('table.entity_id', $user->uid, '=');

$query = db_select('table', 't')
    ->fields('p', array('entity_id', 'value'))
    ->condition('value', $subquery, 'IN')
    ->condition('entity_id', $user->uid, '<>')
    ->orderBy('entity_id', 'ASC')
    ->groupBy('entity_id');
$result = $query->execute();

This query returns multiple rows:

entity_id value

entity_id value

entity_id value

entity_id value

What I need is:

entity_id value, value, value, value

entity_id value, value

entity_id value, value, value

I've searched and searched and cannot figure out how to do this. Can anyone help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.