1
mrgym
addOptionArray inputs should be array(array( ))?
  • 2003/10/22 20:11

  • mrgym

  • Just popping in

  • Posts: 28

  • Since: 2002/4/26


1. Shouldn't addOptionArray take an array of arrays? This is how data comes back from a query.
2. What methods have been used to convert to a one-dimensional array? Most of the examples grep'ed above the modules directory show 'static' input such as

$x->addOptionArray(array('3600' => _HOUR, '18000' => sprintf(_HOURS
, 5));

or I have found examples of a one dimensional array containing text values that was automatically indexed.


I'm creating select options for admin forms using XoopsFormSelect.

The HTML I hope to create is;






so that when the form is posted, I can act on the option value which is the record id.

My database query comes back looking like this (an array or arrays);

$array[0] = array( 'value'=>6,'cat'=>'acategory')
$array[1] = array( 'value'=>2,'cat'=>'bcategory')

and can easily be converted to this;

$array[0] = array('6'=>'acategory')
$array[1] = array('2'=>'bcategory')

addOptionArray would want these to look like this;

$array = array ('6'=>'acategory','2'=>'bcategory')

Before I present my patented kludge for the conversion, I thought I would ask....


2
ackbarr
Re: addOptionArray should be array(array( ))?

Since an option list is name/value pairs, it is reasonable to expect a 1d associative array. The array of arrays solution would need additional parameters to know which field represented the key and which represented the value, or it would have to assume that the first field was the key and the second was the value.

Your solution is fine, but you can make it easier on yourself by using $x->addOption($value, $name=""); while looping through your returned result set.

3
mrgym
Re: addOptionArray should be array(array( ))?
  • 2003/10/23 16:05

  • mrgym

  • Just popping in

  • Posts: 28

  • Since: 2002/4/26


Of course!! (slaps head)

I can iterate though the array of revised associative arrays provided by $xoopsDB->fetchArray(), calling addOptionArray on each iteration. This is the simple way addOptionArray was meant to be used.

It would be great to have a method for adding these options that accepted $array[] = array('key'=>'value'). It would allow 1 return from the database method without adding a function that iterates.






Login

Who's Online

275 user(s) are online (218 user(s) are browsing Support Forums)


Members: 0


Guests: 275


more...

Donat-O-Meter

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

Latest GitHub Commits