1
fiammy
How to fill a combobox from a database table
  • 2007/7/12 9:25

  • fiammy

  • Just popping in

  • Posts: 19

  • Since: 2003/1/14


Hello,
I have a table with categories, and I want the members to choose one of the existing categories when they submit something. Every category has a number, and I want to display the name, while I have to store the number in the second table as reference.

I thought about putting the result in an array and sending that to the template, but that leaves me with the task of doing the reverse mapping between the name and the number, something I would like to evade.

I don't know if there is any best practice for this in the XOOPS world, as this is a fairly used type of component.

Thank you for any insights

2
zyspec
Re: How to fill a combobox from a database table
  • 2007/7/12 13:38

  • zyspec

  • Module Developer

  • Posts: 1093

  • Since: 2004/9/21


If you're using XoopsForm then you can use the 'XoopsFormSelect' function. If the array already exists then you can use the 'addOptionArray' function otherwise you can create the options using the 'addOption' function.

If you're using the Smarty template engine then you must assign your array to the template - For example:
$xoopsTpl->assign('optionArray'$currentArray);
and then use Smarty's 'html_options' function inside the template to display it.

For both of these options the key should be the number you want to use and the value should be set to the name. So the array would look like:
array(4=>'ABC',10=>'QED',13=>'XYZ');

so when the user selects the option they want the value returned will be the key, which is the number.

3
fiammy
Re: How to fill a combobox from a database table
  • 2007/7/15 9:15

  • fiammy

  • Just popping in

  • Posts: 19

  • Since: 2003/1/14


Okay, great Thanks for the answer.

I seem to have a hole in my XOOPS documentation. I'll have a look for the XoopsForm description.

Thanks

Login

Who's Online

74 user(s) are online (34 user(s) are browsing Support Forums)


Members: 0


Guests: 74


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Aug 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits