我試着去插入來自看起來像這樣的表單數據:插入數據
<input type="checkbox" name="single_color_show[]" value="1" id="1" checked>
<input type="text" name="single_color_val[]" class="input-admin-val" value="0" id="1">
<input type="hidden" name="single_color_name[]" value="Vit: (NCS S0502-Y)" id="1">
<input type="hidden" name="single_color_head[]" value="colors" id="1">
<input type="hidden" name="single_color_standard[]" value="1" id="1">
<input type="hidden" name="single_color_order[]" value="1" id="1">
<input type="hidden" name="single_color[]" value="1" id="1"></td>
等等...
我要的是所有值存儲在數據庫中。只要single_color_show被選中,這工作正常。但是我需要插入數據,無論如何,但值爲0而不是1,所以腳本知道它應該隱藏。
這是我的PHP代碼:
$single_color_show = $_POST['single_color_show'];
$single_color = $_POST['single_color'];
$single_color_name = $_POST['single_color_name'];
$single_color_val = $_POST['single_color_val'];
$single_color_head = $_POST['single_color_head'];
$single_color_standard = $_POST['single_color_standard'];
$single_color_order = $_POST['single_color_order'];
foreach($single_color_order as $key => $n) {
$s_color = "INSERT INTO product_attributes (products_id, att_name, att_head, att_val, att_standard, att_order, att_show) VALUES ('".$products_id_enkel."', '".$single_color_name[$key]."', '".$single_color_head[$key]."', '".$single_color_val[$key]."', '".$single_color_standard[$key]."', '".$single_color_order[$key]."', '".$single_color_show[$key]."');";
$q = mysql_query($s_color) or die ('Error posting data enkeldörr färg');
}
只要我把一切都,選項選中它保存數據美麗的溫馨,但因爲我需要檢索的數據爲未來的編輯,我需要所有列出的選去與選擇的屬性。
如果我檢查可以說,2出3,選項的,我想對數據進行存儲,因爲這
products_id, att_name, att_head, att_val, att_standard, att_order, att_show
12 Red Color 80 1 1 1
12 Blue Color 50 0 2 0
12 Green Color 70 0 3 1
這就是我現在得到:
products_id, att_name, att_head, att_val, att_standard, att_order, att_show
12 Red Color 80 1 1 1
12 Green Color 70 0 3 1
+1好的供應碼等,但:如何與att_val記錄從其他= 50種不同記錄? – michi 2013-03-19 21:19:08
我聽到那種諷刺嗎? – Martin 2013-03-19 21:20:37
沒有。我是認真的。 – michi 2013-03-19 21:21:49