Php 如何让此代码将多个值输入回数据库
我已经摆弄这个代码有一段时间了,我无法让它工作!我对这种类型的编码有点不在行,所以当我问任何“愚蠢的问题”时,请记住这一点 基本上,我希望用户能够从数据库生成的列表中选择多个选项,并将其作为自己的选择反馈。目前,它是一个多选框,但它只将一个值输入到db中 任何帮助都将不胜感激。谢谢Php 如何让此代码将多个值输入回数据库,php,html,multiple-select,multipleselection,Php,Html,Multiple Select,Multipleselection,我已经摆弄这个代码有一段时间了,我无法让它工作!我对这种类型的编码有点不在行,所以当我问任何“愚蠢的问题”时,请记住这一点 基本上,我希望用户能够从数据库生成的列表中选择多个选项,并将其作为自己的选择反馈。目前,它是一个多选框,但它只将一个值输入到db中 任何帮助都将不胜感激。谢谢 function ProjectTheme_get_categories($taxo, $selected = "", $include_empty_option = "", $ccc = "") { $args =
function ProjectTheme_get_categories($taxo, $selected = "", $include_empty_option = "", $ccc = "")
{
$args = "orderby=name&order=ASC&hide_empty=0&parent=0";
$terms = get_terms( $taxo, $args );
$ret = '<select multiple size="20" name="'.$taxo.'_cat" class="'.$ccc.'" id="scrollselect '.$ccc.'">';
if(!empty($include_empty_option)) $ret .= "<option value=''>".$include_empty_option."</option>";
if(empty($selected)) $selected = -1;
foreach ( $terms as $term )
{
$id = $term->term_id;
$ret .= '<option '.($selected == $id ? "selected='selected'" : " " ).' value="'.$id.'">'.$term->name.'</option>';
$args = "orderby=name&order=ASC&hide_empty=0&parent=".$id;
$sub_terms = get_terms( $taxo, $args );
foreach ( $sub_terms as $sub_term )
{
$sub_id = $sub_term->term_id;
$ret .= '<option '.($selected == $sub_id ? "selected='selected'" : " " ).' value="'.$sub_id.'"> | '.$sub_term->name.'</option>';
$args2 = "orderby=name&order=ASC&hide_empty=0&parent=".$sub_id;
$sub_terms2 = get_terms( $taxo, $args2 );
foreach ( $sub_terms2 as $sub_term2 )
{
$sub_id2 = $sub_term2->term_id;
$ret .= '<option '.($selected == $sub_id2 ? "selected='selected'" : " " ).' value="'.$sub_id2.'"> |
'.$sub_term2->name.'</option>';
}
}
}
$ret .= '</select>';
return $ret;
}
function ProjectTheme\u get\u categories($taxo,$selected=“”,$include\u empty\u option=“”,$ccc=“”)
{
$args=“orderby=name&order=ASC&hide\u empty=0&parent=0”;
$terms=get_terms($taxo,$args);
$ret='';
如果(!empty($include_empty_option))$ret.=“.$include_empty_option.”;
如果(空($selected))$selected=-1;
foreach($terms作为$term)
{
$id=$term->term\u id;
$ret.=''.$term->name';
$args=“orderby=name&order=ASC&hide\u empty=0&parent=”.$id;
$sub_terms=get_terms($taxo,$args);
foreach($sub_术语作为$sub_术语)
{
$sub_id=$sub_term->term_id;
$ret.='|'.$sub_term->name';
$args2=“orderby=name&order=ASC&hide\u empty=0&parent=”.$sub\u id;
$sub_terms2=get_terms($taxo,$args2);
foreach($sub_terms2作为$sub_term2)
{
$sub_id2=$sub_term2->term_id;
$ret.='|
“.$sub_term2->name.”;
}
}
}
$ret.='';
返回$ret;
}
万一我不太清楚,我的问题是:
如何让上面的代码将多个值输入到数据库中?您是否考虑过将
[]
(给定:name=“”.$taxo.“\u cat[]”“
)添加到select
元素的名称中,以将数组返回到处理脚本中?您好,David,非常感谢您的建议。不幸的是,这个添加意味着它没有选择任何类别