0

我一直在摆弄这段代码,但我无法让它工作!我对这种类型的编码有点菜鸟,所以如果/当我问任何“愚蠢的问题”时,请记住这一点。

基本上我希望用户能够从数据库生成的列表中选择多个选项,并将其作为他们的选择反馈回来。目前它是一个多选框,但它只将一个值输入回数据库。

任何帮助将不胜感激。谢谢

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.'">&nbsp; &nbsp;|&nbsp;  '.$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.'">&nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; 
             '.$sub_term2->name.'</option>';

        }
    }

}

$ret .= '</select>';

return $ret;

}

以防万一我不是很清楚,我的问题是:

如何获取上面的代码以将多个值输入回数据库?

4

0 回答 0