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. Then I need to pull the user name of each result and list with their matching interests. I have a query/subquery script that partially 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();
$items = array();
foreach ($result as $num) {
$items[] = array($num->entity_id);
}
$block['content'] = theme('item_list', array('items' => $items));
This query returns multiple rows:
- entity_id value
- entity_id value
- entity_id value
- entity_id value
What I need is: