By jeepfreak on
I've tried this 20 different ways and I can't figure it out. I want to pull some uid's from my DB, and make a dropdown box (form_select). The trick is that I want the usernames as the values and the uid's as the keys. I've already got a function in place to lookup the usernames - 'member_name()'.
Here's the DB query:
$result = db_query("SELECT group_members.uid FROM (group_members) WHERE group_members.gid = '%d'", $node->gid);
Here's the dropdown:
form_select('dropdown', 'dropdown', NULL, $selections, NULL, 0, FALSE, FALSE);
I want $key to be '$uid' and $value to be 'member_name($uid)'.
I'm using this in the developement of a module. Can anybody help me out? I'm sorry if this is not very clear.
TIA,
Billy
Comments
Um, I think
.. or it may be $selections[member_name($uid)]=$uid;
can't recall.
Is that all you wanted?
.dan.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Hmmm... this seems to be
Hmmm... this seems to be working, but it gives a warning:
"warning: array_pop(): The argument should be an array"
Any idea why?
Thanks,
Billy
You'll get that if it's
You'll get that if it's called on a null result.
Better check if($result) before you get into the while loop.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
but $result should be NULL,
but $result should be NULL, it's got 2 values in it and that is reflected. Sorry, I should just try what you said, but I'm not able to until after work and I'm curious now =)
Thanks a lot!
Billy
EDIT - I just tried your solution and it doesn't change anything. :confused:
This would be cake if had
This would be cake if had PHP5 =(
array_combine()
Billy
EDIT: This function got it to work:
Now... one last question...
Now... one last question... how could I add a "none" option? It doesn't even have to be a selectable option, just the default choice?
Thanks,
Billy