修改php购物车以支持多个下拉菜单
我有一个购物车脚本,我正试图修改它以支持多种产品选择。现在,客户可以从单个下拉菜单中选择产品。现在,我想添加多个下拉菜单,所有下拉菜单都使用相同的选项填充 以下是输出下拉菜单的php:修改php购物车以支持多个下拉菜单,php,menu,shopping-cart,Php,Menu,Shopping Cart,我有一个购物车脚本,我正试图修改它以支持多种产品选择。现在,客户可以从单个下拉菜单中选择产品。现在,我想添加多个下拉菜单,所有下拉菜单都使用相同的选项填充 以下是输出下拉菜单的php: if($eshopoptions['options_num']>1){ $opt=$eshopoptions['options_num']; $replace.="\n".'<label for="eopt'.$theid.'"><selec
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";
}
}
有没有什么简单的方法可以让代码输出菜单,比如说3次而不是一次?除非您真的需要冗余,否则您可以允许用户通过将多个属性和可选的大小属性添加到您的选择标记来选择多个选项:
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";
}
}
如果选择此解决方案,可能需要添加有关如何通过按住ctrl键并单击多个选项来选择多个选项的说明。