【发布时间】:2021-07-02 02:11:45
【问题描述】:
首先,我很抱歉,因为我还是个新手,想了解更多关于编码的知识。
我目前正在处理这个问题。 我的第一张、第二张和第三张桌子工作正常。我的问题是我的第四张桌子没有收到任何值。 我尝试使用 $eGrad 等于 Grade Level 的 switch 语句在我的第四张表上插入数据。 我想根据年级在我的 st_grade 表(第 4 个表)上插入值,其中一些是常量值。
我将不胜感激。谢谢! 这是我正在工作的代码
public function insert($stID, $eFullname, $eGrad, $secID, $eStatus, $eSY, $syID, $rformOne, $rformTwo, $rPsa, $rGm, $rPic){
$firstTB = "INSERT INTO st_enrolled (e_stid, e_fullname,e_grade,e_status,e_sy) VALUES('$stID', '$eFullname', '$eGrad', '$eStatus', '$eSY')";
$secondTB = "INSERT INTO st_sy (st_sy_stid, st_sy_syid) VALUES('$stID', '$syID')";
$thirdTB = "INSERT INTO st_requirement (str_id, str_fullname, formOne, formTwo, psa, goodmoral, picture) VALUES ('$stID', '$eFullname', '$rformOne', '$rformTwo', '$rPsa', '$rGm', '$rPic')";
switch($eGrad){
case "Grade1" :
$fourthTB = "INSERT INTO `st_grade`(`st_id`,`subj_id`,`gr_id`,`sec_id`,`sy_id`,`first`,`second`,`third`,`fourth`,`ave`,`remarks`) VALUES
($stID, 1, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 2, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 3, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 4, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 5, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 6, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 7, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),";
break;
case "Grade2" :
$fourthTB = "INSERT INTO `st_grade`(`st_id`,`subj_id`,`gr_id`,`sec_id`,`sy_id`,`first`,`second`,`third`,`fourth`,`ave`,`remarks`) VALUES
($stID, 8, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 9, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 10, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 11, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 12, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 13, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),
($stID, 14, $eGrad, $secID, $syID, 0, 0, 0, 0, 0, ''),";
break;
default:
echo "error";
}
if ($this->conn->query($firstTB) && $this->conn->query($secondTB) && $this->conn->query($thirdTB) && $this->conn->query($fourthTB) ) {
return true;
} else {
return false;
}
}
【问题讨论】:
-
到底是什么问题?你的问题到底是什么?查看如何create a Minimal, Reproducible Example
标签: php mysql sql switch-statement sql-insert