如果echo语句已由if语句触发,我的目标是将相应的学习方式插入到数据库中。 DB列如下:studentNumber,dimension1,dimension2,dimension3,dimension4。对于任何反馈,我们都表示感谢。试用“温和活跃”,因此该声明只出现在代码的那个阶段。
<?php
$active =0;
$reflective=0;
$sensing=0;
$intuitive=0;
$visual=0;
$verbal=0;
$sequential=0;
$global=0;
$mildlyActive = "Mildly Active";
$moderatelyActive = "Moderately Active";
$stronglyActive = "Strongly Active";
$mildlyReflective = "Mildly Reflective";
$moderatelyReflective = "Moderately Reflective";
$stronglyReflective = "Strongly Reflective";
if(isset($_POST['submit'])){
foreach($_POST as $key=>$value){
if($key != "submit"){
$dbQuery1 = $db->prepare("select * FROM answer WHERE answerID = '".$value."'");
$dbQuery1-> execute();
while ($dbRow = $dbQuery1->fetch (PDO::FETCH_ASSOC)){
$answerTypeID=$dbRow["answerTypeID"];
$dbQuery2 = $db->prepare("select * FROM answerType WHERE answerTypeID = '".$answerTypeID."'");
$dbQuery2-> execute();
while ($dbRow2=$dbQuery2->fetch()){
$answerType=$dbRow2["answerType"];
//echo $answerType;
if ($answerType=='active'){
$active++;
}
if ($answerType=='reflective'){
$reflective++;
}
if ($answerType=='sensing'){
$sensing++;
}
if ($answerType=='intuitive'){
$intuitive++;
}
if ($answerType=='visual'){
$visual++;
}
if ($answerType=='verbal'){
$verbal++;
}
if ($answerType=='sequential'){
$sequential++;
}
if ($answerType=='global'){
$global++;
}
}
}
$dbQuery=$db->prepare("INSERT INTO `userResponse` VALUES (:studentID, :questionID, :answerID)");
$dbParams=array('studentID'=>$_SESSION["currentUser"], 'questionID'=>$key, 'answerID'=>$value);
$dbQuery->execute($dbParams);
}
}
}
if ($active>$reflective){
$total = $active - $reflective;
if ($total == 1){
echo "Mildly active";
$dbQuery=$db->prepare("INSERT INTO indexLearningStyle (dimension1) VALUE (:mildlyActive)");
}
if ($total == 2){
echo "Mildly active";
$dbQuery=$db->prepare("INSERT INTO indexLearningStyle (dimension1) VALUE (:mildlyActive)");
}
if($total == 3){
echo "Moderately active";
}
if($total == 4){
echo "Moderately active";
}
if ($total == 5){
echo "Strongly active";
}
}
else {
$total = $reflective - $active;
if ($total == 1){
echo "Mildly reflective";
}
if ($total == 2){
echo "Mildly reflective";
}
if ($total == 3){
echo "Moderately reflective";
}
if ($total == 4){
echo "Moderately reflective";
}
if ($total == 5){
echo "Strongly reflective";
}
}
if ($sensing>$intuitive){
$total = $sensing - $intuitive;
if ($total == 1){
echo "Mildly sensing";
}
if ($total == 2){
echo "Mildly sensing";
}
if($total == 3){
echo "Moderately sensing";
}
if($total == 4){
echo "Moderately sensing";
}
if ($total == 5){
echo "Strongly sensing";
}
}
else {
$total = $intuitive - $sensing;
if ($total == 1){
echo "Mildly intuitive";
}
if ($total == 2){
echo "Mildly intuitive";
}
if ($total == 3){
echo "Moderately intuitive";
}
if ($total == 4){
echo "Moderately intuitive";
}
if ($total == 5){
echo "Strongly intuitive";
}
}
if ($visual>$verbal){
$total = $visual - $verbal;
if ($total == 1){
echo "Mildly visual";
}
if ($total == 2){
echo "Mildly visual";
}
if($total == 3){
echo "Moderately visual";
}
if($total == 4){
echo "Moderately visual";
}
if ($total == 5){
echo "Strongly visual";
}
}
else {
$total = $verbal - $visual;
if ($total == 1){
echo "Mildly verbal";
}
if ($total == 2){
echo "Mildly verbal";
}
if ($total == 3){
echo "Moderately verbal";
}
if ($total == 4){
echo "Moderately verbal";
}
if ($total == 5){
echo "Strongly verbal";
}
}
if ($sequential>$global){
$total = $sequential - $global;
if ($total == 1){
echo "Mildly sequential";
}
if ($total == 2){
echo "Mildly sequential";
}
if($total == 3){
echo "Moderately sequential";
}
if($total == 4){
echo "Moderately sequential";
}
if ($total == 5){
echo "Strongly sequential";
}
}
else {
$total = $global - $sequential;
if ($total == 1){
echo "Mildly global";
}
if ($total == 2){
echo "Mildly global";
}
if ($total == 3){
echo "Moderately global";
}
if ($total == 4){
echo "Moderately global";
}
if ($total == 5){
echo "Strongly global";
}
}
?>