Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
straight from 'dbQuery' to 'jmChoose' without a FOREACH
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

Posted: 05/12/09 16:19 
Yes - you can do this. You just need to define the column to want to return as the 5th argument, and the second argument needs to be the key - i.e.


Code

$req = "SELECT band_id, band_name
          FROM {$jamroom_db['band_info']}";
$_rt = dbQuery($req,'band_id',null,false,'band_name');


You'll get the array you want as $_rt.

Hope this helps!

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/12/09 18:01 
Champion!!

Thought you would have built in some feature to make life easier.

Awesome, thanks. Smile


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.