如何让此代码将多个值输入数据库

时间:2013-11-16 13:07:15

标签: php html multiple-select multipleselection

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

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

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

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;

}

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

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

0 个答案:

没有答案