我有2个数组(作为示例,但我有8个),将记录插入到MySQL数据库中。但是我对如何插入它们感到困惑。请指导我。
$bunit = $_POST['bunit'];
$prodID = $_POST['productID'];
$section = $_POST['section'];
$remarks = array();
$remarksType = array();
INSERT INTO `remarks` (`remarks_id`, `remarks`,`bunit`, `prodID`, `remarks_section_ID`, `remarks_type`, `remarks_defectID`, `remarks_productID`, `remarks_active`) VALUES (NULL, '$remarks', '$bunit', '$prodID', '$section', '$remarksType', '1', '2', 1);"
答案 0 :(得分:-1)
嘿,在插入之前,您需要做一件事,将数组编码为json_encode()并在从数据库中检索时插入到db中,只需使用json_decode()即可
$bunit = $_POST['bunit'];
$prodID = $_POST['productID'];
$section = $_POST['section'];
$remarks = json_encode(array('id'=>1 ,'data'=>'remarks')) ;
$remarksType = json_encode(array('id'=>1 ,'data'=>'remarksType'));
$sql = "INSERT INTO `remarks` (`remarks_id`, `remarks`,`bunit`, `prodID`, `remarks_section_ID`, `remarks_type`, `remarks_defectID`, `remarks_productID`, `remarks_active`) VALUES (NULL, '$remarks', '$bunit', '$prodID', '$section', '$remarksType', '1', '2', 1);"