我需要幫助的checkboxe三個表之間的鏈接:PDO多個checkboxs插入或刪除
功能表(ID,標題,sulg)
職位表(ID,標題,蛞蝓,加)
posts_features(fea_id,POST_ID)
<input type="text" name="title" value="$post->title">
<input type="text" name="slug" value="$post->slug">
// importing all features
<input type="checkbox" name="featuresid[]" value="$features->id">
如果選中(插入)如果不存在。
foreach ($_POST['featuresid'] as $choice) {
$sql = $dbh->prepare("INSERT INTO posts_features (fea_id, post_id) VALUES ($choice, $id)");
$sql->execute();
}
如果未覈對(刪除)posts_features
$sql = $dbh->prepare("delete form posts_features where ........
在此先感謝。
尼斯的答案。我考慮過這一點,但擔心複選框列表可能只是所有post_features的一個子集,而不是完整的列表。 (例如,如果分頁)。 –