Posted by maori on March 18, 2010 at 8:53pm
Hi Guys
can someone explain to me how i can get a full list of users into a select form element please
i have managed to get my own name in but none others
TIA
Hi Guys
can someone explain to me how i can get a full list of users into a select form element please
i have managed to get my own name in but none others
TIA
Comments
Directly from the database
function _pruebas_form1() {
$form [ 'user_select'] = array (
'#title' => t ( 'Choose the user'),
'#type' => 'select',
'#options' => _getAllUsers(),
'#description' => 'Choose the user',
);
$form [ 'submit'] = array (
'#type' => 'submit',
'#value' => t ( 'submit'),
);
return $form;
}
/*
This function gets as all users in the database.
if you only want the active users then
$query = "select uid, name from users where uid > 0 and status = 1";
*/
function _getAllUsers() {
$query = "select uid, name from users where uid > 0";
$result = db_query($query);
$users = array();
while ($user = db_fetch_object($result)){
$users[$user->uid] = $user->name;
}
return $users;
}
user_search() (API) can also be used but for me it is more difficult.
Thankyou worked like a charm
Thankyou
worked like a charm :D