Forums

Creating a dropdown of specific users

kmedri 17 Nov, 2011
Hi,
Joomla 1.7.3 and chronoforms v4rc2
I am trying to add a select drop down that will list users in a specific group.
I am trying to acheive this but not sure where to add or how to modify this code to work in j1.7:
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
SELECT '#__user_usergroup_map.group_id', '#__users.id', '#__users.name'
FROM '#__user_usergroup_map', '#__users'
WHERE '#__user_usergroup_map.group_id' = 10;
";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
echo "<option value='".$o[id]."'>".$o[name]."</option>";
}
?>

Any help would be greatly appreciated.
kmedri 21 Nov, 2011
My bad, the code was wrong, what I did was to add the code directly and changed to

<option value="" selected>Please Select</option>
    <?php
    if (!$mainframe->isSite() ) {return;}
    $db =& JFactory::getDBO();
    $query = "
    SELECT #__users.id, #__users.name
    FROM #__user_usergroup_map, #__users
    WHERE #__user_usergroup_map.user_id = #__users.id
    AND #__user_usergroup_map.group_id = 10 ;
    ";
    $db->setQuery($query);
    $options = $db->loadAssocList();
    foreach ( $options as $o ) {
    echo "<option value=".$o[id].">".$o[name]."</option>" ;
    }
    ?>


I had to remove all the colons. Just in case this is useful for someone else!
GreyHead 24 Nov, 2011
Hi kmedri ,

Well found - MySQL queries need back-ticks `` round table and column names (straight quotes '' are for string values).

Bob
This topic is locked and no more replies can be posted.