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?
在foreach
循环结束后使用$ key,并且由于对php关联数组进行了排序,因此$ key等于循环结束前的最后一个值是4。这就是为什么要插入4的原因。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.