Forgive me - pretty much a Joomla/SQL rookie and trying to navigate through some tasks I trying to help my local home owners association with. I'm looking for a way to build my own user list containing multiple custom user fields. My current query gives me multiple records for each user because each user is linked to multiple fields in the "__fields_values" table. I need only ONE record for each user and each custom field as a seperate value in this row. A simple group clause doesn't seem to cut it. Nevermind the actual table html, that's just for testing right now. Hope someone can help me see the light :)
Now I get:
username1|field1|<blank>|email
username1|field2|<blank>|email
My table should look like:
username1|field1|field2|email
My current query and output:
$query = $db->getQuery(true);
$query
->select('*')
->from($db->quoteName('#__users', 'u'))
->join('INNER', $db->quoteName('#__user_usergroup_map', 'm') . ' ON (' . $db->quoteName('u.id') . ' = ' . $db->quoteName('m.user_id') . ')')
->join('INNER', $db->quoteName('#__fields_values', 'f') . ' ON (' . $db->quoteName('u.id') . ' = ' . $db->quoteName('f.item_id') . ')')
->where($db->quoteName('group_id') . ' = ' . $group_id)
->order($db->quoteName('u.username') . ' ASC')
$db->setQuery($query);
$users = $db->loadObjectList();
And then output to this table:
<table style="width:100%">
<tr style="border-bottom:1pt solid black;text-align: left;">
<th>Name</th>
<th>CustomField1</th>
<th>CustomField2</th>
<th>Email</th>
</tr>
<?php
foreach($users AS $user)
{
?>
<tr>
<td><?php;
echo $user->name;
?></td>
</td>
<td><?php;
echo $user->value;
?></td>
<td><?php;
echo $user->NEED ANOTHER VALUE HERE;
?></td>
<td><?php;
echo $user->email;
}?>
</table>