$ selected在重新加载后未显示,但保存在数据库中

时间:2014-02-10 16:27:48

标签: javascript php select option taxonomy

我有这个PHP脚本:

<select name="product_type_google" id="product_type_google" style="width: 300px;">
    <?php
        require_once plugin_dir_path( __FILE__ ) . 'google_taxanomy.php';
        $vybrane_google = $_POST["product_type_google"];
        $g1 = '';
        $g2 = '';

        foreach ( _g_google_gelect_options() as $moznost_google ) {
            $google_hodnota = $moznost_google['google_hodnota'];
            if ( $vybrane_google == $moznost_google['google_hodnota'] ) // Make default first in list
                $g1 .= "\n\t<option style=\"padding-right: 10px;\" selected='selected' value='" . esc_attr( $moznost_google['google_hodnota'] ) . "'>$google_hodnota</option>";
            else
                $g2 .= "\n\t<option style=\"padding-right: 10px;\" value='" . esc_attr( $moznost_google['google_hodnota'] ) . "'>$google_hodnota</option>";
        }
        echo $g1 . $g2;
    ?></select>

它工作正常,但是当我选择选项,保存并重新加载页面时,它不显示所选选项。但我可以在数据库中看到该选项已保存。

这会加载选项:

require_once plugin_dir_path( __FILE__ ) . 'google_taxanomy.php';

来自“kategorie.php”,在此文件中,有谷歌分类,例如:

function _g_google_gelect_options() {
    $google_gelect_options = array(
        '0' => array( 'value' => '0', 'label' => '' ),
        '1    ' => array( 'value' =>    '1    ', 'label' => __( 'Animals & Pet Supplies', '_g' ) ), 
        '2    ' => array( 'value' =>    '2    ', 'label' => __( 'Animals & Pet Supplies &gt; Live Animals', '_g' ) ), 
        '3    ' => array( 'value' =>    '3    ', 'label' => __( 'Animals & Pet Supplies &gt; Pet Supplies', '_g' ) ), 
        '4    ' => array( 'value' =>    '4    ', 'label' => __( 'Animals & Pet Supplies &gt; Pet Supplies &gt; Bird Supplies', '_g' ) ), 
        '5    ' => array( 'value' =>    '5    ', 'label' => __( 'Animals & Pet Supplies &gt; Pet Supplies &gt; Bird Supplies &gt; Bird Cages & Stands', '_g' ) ), 
        '6    ' => array( 'value' =>    '6    ', 'label' => __( 'Animals & Pet Supplies &gt; Pet Supplies &gt; Bird Supplies &gt; Bird Food', '_g' ) ), 

此文件包含超过5800行!可能是因为它吗?我应该使用一些JavaScript吗?

你能帮帮我吗?谢谢

0 个答案:

没有答案