[英]how to get joomla select box value
I need to add some small functionality to my admin side of joomla. 我需要在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 ()
. 当前,当用户选择并保存时,总是将
4
插入db ()
。 How can I insert the selected values? 如何插入选择的值?
在foreach
循环结束后使用$ key,并且由于对php关联数组进行了排序,因此$ key等于循环结束前的最后一个值是4。这就是为什么要插入4的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.