如何从三个不同的表中向表中插入总值

时间:2019-07-06 10:48:07

标签: php mysqli

我有3种形式(演示,研讨会,论文),它们使用JavaScript来计算许多学生每次评估的总数。每个表(有3个表pres_tbl,temporary_tbl和essay_tbl)均以正确的总数正确更新。总计也正确插入到第四张表(final_totals)中。然后,我需要将3个评估的结果相加,得出总计。总计需要插入表中。我不知道该怎么办。

我可以将这3个评估加在一起并显示在页面上,但无法计算出总计。将来自多个表的单个评估总计插入另一个表(final_totals)不是问题。

<?php
$con=mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if ( mysqli_connect_errno() ) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query_rs = "UPDATE pres_tbl SET reading='$reading', task='$task', projection_pacing='$projection_pacing', 
nonverbal_communication='$nonverbal_communication', cohesion_coherence='$cohesion_coherence', slides='$slides', contribution='$contribution', 
lexis='$lexis', grammar='$grammar', pronunciation='$pronunciation', numfail='$numfail', presentation_total='$presentation_total', 
presentation_grade='$presentation_grade', percentscore='$percentscore', numfailmacro ='$numfailmacro', comments='$comments', note='$note', 
submission='$submission', warn1='$warn1', warn2='$warn2' WHERE pres_tbl.id='$id'";


$query_rs1 = "UPDATE final_totals SET presentation_total='$presentation_total' WHERE final_totals.id='$id'";

$result = mysqli_query( $con, $query_rs );
$result1 = mysqli_query($con, $query_rs1);
if ( $result ) {
    echo "<br><div><center><h2>Record " . $id .  " updated successfully" . "<br><br>";
    echo $count;
    echo "<a href='presentation.php'>View result</a></h2></center></div>" . "<br>";
} else {
    echo "ERROR";
}
?>

0 个答案:

没有答案