0

複数の製品の選択をサポートするために変更しようとしているショッピングカートスクリプトがあります。現在のように、顧客は単一のドロップダウンメニューから製品を選択できます。ここで、複数のドロップダウンメニューを追加したいと思います(すべて同じオプションが入力されています)。

ドロップダウンメニューを出力するphpは次のとおりです。

if($eshopoptions['options_num']>1){
            $opt=$eshopoptions['options_num'];
            $replace.="\n".'<label for="eopt'.$theid.'"><select id="eopt'.$theid.'" name="option">';
            for($i=1;$i<=$opt;$i++){
                $option=$eshop_product['products'][$i]['option'];
                $price=$eshop_product['products'][$i]['price'];
                if($option!=''){
                    if($price!='0.00')
                        $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).' @ '.sprintf( _c('%1$s%2$s|1-currency symbol 2-amount','eshop'), $currsymbol, number_format($price,2)).'</option>'."\n";
                    else
                        $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).'</option>'."\n";
                }


            }

コードにメニューを1回ではなく3回出力させる本当に簡単な方法はありますか?

4

1 に答える 1

0

本当に冗長性が必要な場合を除いて、ユーザーが複数のオプションを選択できるようにするには、選択タグに複数の属性と、オプションでサイズ属性を追加します。

if($eshopoptions['options_num']>1){
        $opt=$eshopoptions['options_num'];
        $replace.="\n".'<label for="eopt'.$theid.'"><select id="eopt'.$theid.'" name="option" multiple="multiple" size="'.$opt.'">';
        for($i=1;$i<=$opt;$i++){
            $option=$eshop_product['products'][$i]['option'];
            $price=$eshop_product['products'][$i]['price'];
            if($option!=''){
                if($price!='0.00')
                    $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).' @ '.sprintf( _c('%1$s%2$s|1-currency symbol 2-amount','eshop'), $currsymbol, number_format($price,2)).'</option>'."\n";
                else
                    $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).'</option>'."\n";
            }


        }
于 2010-05-18T16:19:15.637 に答える