我想將多個下拉選擇保存到數據庫的一列中。將多個選擇下拉列表保存爲1列
我有以下幾點:
<select name="pack_choice[]" style="width:270px; margin-bottom:2px;">
<option value=''>---Select---</option>
<?php
$query = mysql_query("SELECT * FROM tbl_package_source where pack_type = 'Bronze' AND pack_desc = 'Pasta/Noodles/Vegetables'");
while ($row = mysql_fetch_array($query)){
$pack_id = $row['pack_code'];
echo "<option value='".$row['pack_code']."'>".$row['pack_part']."</option>";
} ?>
</select>
<select name="pack_choice[]" style="width:270px; margin-bottom:2px;">
<option value=''>---Select---</option>
<?php
$query1 = mysql_query("SELECT * FROM tbl_package_source where pack_type = 'Bronze' AND pack_desc = 'Seafoods'");
while ($row = mysql_fetch_array($query1)){
$pack_id = $row['pack_code'];
echo "<option value='".$row['pack_code']."'>".$row['pack_part']."</option>";
}
?>
</select><br/>
,這裏是我的查詢
$pack_choice = implode(", ",$_POST['pack_choice']);
$qry = "Insert INTO tbl_packages (pack_choice) VALUES ('{$pack_choice}')";
$result_set = mysql_query($qry);
我知道這不是你的問題,但可能在一列中存儲2個值不是最好的解決方案。因爲當從數據庫中檢索數據時,你必須再次分割這些值(並且假設沒有缺失並且按正確的順序)。 – Wietze314