0

I need to add some small functionality to my admin side of joomla.

I want it so when the user selects a value from drop... selected values are then inserted into my database.

Here is the code:

$default = 2;
$months = array(1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr');
$options = array();
foreach($months as $key=>$value) :
$options[] = JHTML::_('select.option', $key, $value);
endforeach;

$dropdown = JHTML::_('select.genericlist', $options, 'month', 'class="inputbox"' ,'value', 'text', $default);

echo $dropdown;

$object = new stdClass();
$object->virtuemart_product_id = $this.id;
$object->brightness = $key; 
try {
    $result = JFactory::getDbo()->updateObject('#__virtuemart_product_prices', $object, 'virtuemart_product_id');
    } catch (Exception $e) {
            // catch the error.
 }

Currently, when the user selects and saves, it always inserts 4 into db (). How can I insert the selected values?

stevenspiel
  • 5,775
  • 13
  • 60
  • 89
lordman
  • 15
  • 5

1 Answers1

0

You are using $key after your foreach loop has ended and since php associative arrays are ordered the last value that $key was equal to before the loop ended was 4. That is why it is inserting 4.

elitechief21
  • 2,964
  • 1
  • 17
  • 15
  • yes u r write. i know this... actually this is for getting values from array and display in select box. i just want when user select month from select box.... selected month's values inserted into db.. – lordman Dec 19 '13 at 14:43