drupal形式のAPIで選択するキー(type_id)と値(type_description)を追加したい
$result_x->product_types->RPMProductType はデータベースからの配列結果です:- array(4) { [0]=> object(stdClass)#18 (2) { ["type_description"]=> string(10) "Calendered" [ "type_id"]=> int(1) } [1]=> object(stdClass)#19 (2) { ["type_description"]=> string(8) "Extruded" ["type_id"]=> int(2) ) } [2]=> object(stdClass)#20 (2) { ["type_description"]=> string(6) "Molded" ["type_id"]=> int(3) } [3]=> object( stdClass)#21 (2) { ["type_description"]=> string(5) "その他" ["type_id"]=> int(4) } }
foreach ($result_x->product_types->RPMProductType as $data) { $form['manufacturer_add_new_sales']['product_type'] = array( '#type' => 'select', '#title' => t('商品タイプ'), '#options'=>array($data->type_id=>$data->type_description), ); }
そうするとき、最後の値、つまりその他のみを取得しています。正しくループしてバインドする方法 すべての配列キー - 値を表示するように選択します。
前もって感謝します。