首先,我的想法是在我的数据库中存储多个复选框。
if (in_array(",", $_POST['categories'])) { /* Other was selected */}
$cat = implode(" ,", $_POST['categories']);
if (in_array(",", $_POST['subcat'])) { /* Other was selected */}
$sub = implode(" ,", $_POST['subcat']);
if (in_array(",", $_POST['type'])) { /* Other was selected */}
$type = implode(" ,", $_POST['type']);
if (in_array(",", $_POST['payment'])) { /* Other was selected */}
$payment = implode(" ,", $_POST['payment']);
我读过一些文章说这是错误的,所以我为上面的每个值设置了一些新表。($ cat,$ sub,$ type,$ payment)。
所有这些都是这样的:
Destination_id | category_id
444 5
444 22
444 30
有了这个说我想要一些帮助,如何使我的循环存储各种表中的所有值。像上面一样。所以我可能会在以后的搜索中使用它们。
编辑:这是我的插入顺便说一句,它将有其他值。
$sql = "INSERT INTO tbl_locations SET
name='".$_POST['name']."',
alias='".$_POST['alias']."',
category_id='$cat',
subcategory_id='$sub',
tourism_type_id='$type',
lgu_id='$payment',
latitude='".$_POST['latbox']."',
longitude='".$_POST['lngbox']."'
";
编辑:对不起,我的不好就是这样。
<input type="checkbox" name="categories[]" value=2 id=Food and Drink><label for=Food and Drink class="fil_lab">Food and Drink</label>
<input type="checkbox" name="categories[]" value=7 id=Nightlife and Entertainment><label for=Nightlife and Entertainment class="fil_lab">Nightlife and Entertainment</label>
<input type="checkbox" name="categories[]" value=1 id=Place to Stay><label for=Place to Stay class="fil_lab">Place to Stay</label>
<input type="checkbox" name="categories[]" value=4 id=Point of Interest><label for=Point of Interest class="fil_lab">Point of Interest</label>
<input type="checkbox" name="categories[]" value=6 id=Shopping><label for=Shopping class="fil_lab">Shopping</label><br><br>
<input type="checkbox" name="categories[]" value=5 id=Spa and Wellness><label for=Spa and Wellness class="fil_lab">Spa and Wellness</label>
<input type="checkbox" name="categories[]" value=3 id=Tourist Attraction><label for=Tourist Attraction class="fil_lab">Tourist Attraction</label>