次のようなテーブルがあります。
+--------+---------------+--------------+---------------+
| id | firstname | lastname | foods |
+--------+---------------+--------------+---------------+
| 1 | James | Bonds | BBQ |
| 2 | James | Bonds | Hamburger |
| 3 | James | Bonds | Pizza |
| 4 | David | Smith | BBQ |
| 5 | David | Smith | Pizza |
+--------+---------------+--------------+---------------+
これは、データベースに挿入するときの私のコードです:
if($_POST["Submit"]=="Submit"){
for ($i=0; $i<sizeof($checkbox);$i++){
$sql="INSERT INTO tbl_info VALUES ('NULL', '$fname','$lname', '".$checkbox[$i]."')";
$result=mysql_query($sql);
}
}
または、次のようにすることは可能ですか?
+--------+---------------+--------------+---------------+
| id | firstname | lastname | foods |
+--------+---------------+--------------+---------------+
| 1 | James | Bonds | BBQ |
| 1 | James | Bonds | Hamburger |
| 1 | James | Bonds | Pizza |
| 2 | David | Smith | BBQ |
| 2 | David | Smith | Pizza |
+--------+---------------+--------------+---------------+
'foods' 列はチェック ボックスの値であるため、冗長になりました (ユーザーが 10 個のチェック ボックスの値を選択した場合、同じ名を持つ 10 行も生成されます)。
The problem is if I need to alter the information of the user, I have to alter it 1 by 1 and that's so wrong. And if I am going to delete the users information, the training column values should also be deleted all at once.(I must not use implode or explode). I'm sorry. new to php.
Thanks in advance.