2013-12-19 68 views
0

我需要添加一些小功能到我的joomla管理端。如何獲取joomla選擇框的值

我想要它,所以當用戶從drop中選擇一個值時...然後將選定的值插入到我的數據庫中。

下面是代碼:

$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. 
} 

目前,用戶選擇時並保存,它總是插入4db()。我如何插入選定的值?

回答

0

您正在使用$鍵您foreach循環結束後,因爲PHP關聯數組是有序的最後值$關鍵是等於之前的循環結束了4.這就是爲什麼它被插入4.

+0

是你寫。我知道這......實際上這是爲了從數組中獲取值並在選擇框中顯示。我只想當用戶從選擇框中選擇月份....選擇月份的值插入到數據庫.. – lordman