簡體   English   中英

Drupal:如何從Select Option更新數據庫

[英]Drupal: How to update database from Select Option

大家好,我真的是Drupal的新手,現在已經從數據庫中選擇了我需要的所有數據並將其顯示在下拉列表中,從而陷入困境。 不幸的是,由於我沒有任何價值,因此我不知道如何使用此特定選定字段更新數據庫。

$options = array();
foreach ($results as $result) {
$options["name"] = array(
$result->name,
);
}

$options2 = array();
foreach ($results_tour as $result2) {
$options2[$result2->sku] = array(
$result2->title,
    );
    }

$form['tour'] = array(
'#type' => 'select',
'#options' => $options2,
);

$form['tour_guide'] = array(
'#type' => 'select',
'#title' => t('Tour Guide'),
'#options' => $options,
'#description' => 'Please select a guide for this specific tour'
);

$form['save'] = array(
'#type' => 'submit',
'#value' =>  'Speichern',
'#submit' =>  array('plantours_form_submit'),
);

return $form;

}

function plantours_form_submit($form, $form_state) {

db_update('commerce_line_item')
->fields(array(
'status' => $options["name"]
))
->execute();  
}

不要通過直接寫入數據庫來手動進行操作,而是使用Drupal Commerce API(我想您正在使用Drupal Commerce):

https://www.drupal.org/node/1288414

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM