我试着去插入来自看起来像这样的表单数据:插入数据
<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