Michael
Jamroom Team
Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo
Posted: 05/12/09 02:26
is there a way to get a keyed array from 2 columns in the database?
I have 2 columns in the database
* ID * | * groupname * |
1 first group name
2 second group name
3 third group name
and want an array like this
1->first group name
2->second group name
3->third group name
so that i can give it straight to the 'jmChoose' function without having to step through it in a foreach loop. is it possible?
this is the current code, and i think the key is something to go where the current 'ID' is, but not sure what.
Code $_groups = dbQuery("select * from {$jamroom_db['groups']}", 'ID');
jmChoose('Group','group',$_groups, $_selected, 'no', false ,"Select the group you'd like.",'group report viewing.');
the docs http://www.jamroom.net/Function_dbQuery seam to indicate that $column can be used so i think i need something like
'ID=>groupname' but am unsure of the syntax.
which would then produce:
<option value="1">first group name</option>
<option value="2">second group name</option>
<option value="3">third group name</option>
thanks
--edit--
still interested to know if its possible, but i went through a very small foreach and got is sorted.
Code foreach($_ret as $key => $_vl){
$_groups[$key] = $_vl[groupname];
}
_________________ Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Brian
Jamroom Team
Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA
Back to top
Michael
Jamroom Team
Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo
Back to top