-1
<!-- html code -->
<form id="wpsc-settings-form" action="" method="post">
<tr class="rate_row">
<td> 
    <input type="text" style="width:160px;" value="3000" name="zipcode[]">
</td>
<td>
    <select multiple="" name="city[]">
        <option value="Abbotsford">Abbotsford</option>
        <option value="Aberfeldie">Aberfeldie</option>
        <option value="Airport West">Airport West</option>
    </select>
</td>
 <td> 
   <input type="text" style="width:160px;" value="3000" name="zipcode[]">
</td>
<td>
    <select multiple="" name="city[]">
        <option value="Abbotsford">Abbotsford</option>
        <option value="Aberfeldie">Aberfeldie</option>
        <option value="Airport West">Airport West</option>
    </select>
</td>
</tr>    
</form>

在此处输入图像描述

<!-- php code -->
<?php
        $options = $_POST['zipcode'];
        $city = $_POST['city'];  
        $serializeoption = serialize($city);

        foreach($city as $key => $value){
            $simple_shipping_options_city[$options[$key]] = $value;
        }

        echo "<pre>";
        print_r($simple_shipping_options_city);
        echo "</pre>";

        update_option('wpsc_simple_shipping_city', $simple_shipping_options_city); // update query
?>  

上面的代码按以下方式工作。如果我选择一个城市输出是这样的:

 Array
(
[3000] => Abbotsford
[2000] => Airport West
)  

如果我选择多个城市不传递输入字段值。

我想针对多个城市保存单个邮政编码。您能否提供上述代码的改进建议?

4

1 回答 1

0

首先,在这一行

print_r($simple_shipping_options_city);

simple_shipping_options_city是一个数组。您需要告诉数组您想查看哪个索引。

于 2013-05-03T06:01:16.747 回答