i have 3 tables named 'listening', 'structure' and 'reading'. i want to take data from that tables which has the same id and calculate it then insert it to 'final_score' table. but, the error is: score and right_answer from 'listening' and 'structure' tables was wrong. just score and right_answer from 'reading' is right.
error on $ex=mysql_query($query);
first, user do listening test, then system will save listening score to 'listening' table. and then directly go to structure test and system will save structure score in 'structure' table. finally, user do reading test, and system will take score from that 3 tables.
result_reading.php
<?php
include "connection.php";
$right= 0;
$wrong= 0;
if (isset($_POST["question"])){
foreach($_POST['question'] as $key
=> $value){
$cek = mysql_query("SELECT * FROM reading WHERE no=$key");
while($c = mysql_fetch_array($cek)){
$answer= $c['answer'];
}
if($value==$answer){
$right++;
}else{
$wrong++;
}
}
if ($right==50) {
$score=67;
}elseif ($right==39) {
$score=66;
}elseif ($right==39) {
$score=65;
....
else {
$score=22;
}
$email = $_SESSION['email'];
$simpan = "INSERT INTO reading VALUES ('$email', '$right', '$score')";
$query ="SELECT reading.id,structure.id,right_structure,score_structure,listening.id,right_listening,score_listening FROM reading,structure,listening WHERE reading.id=structure.id and reading.id=listening.id";
$ex=mysql_query($query);
$data=mysql_fetch_array($ex);
$benar_structure = $data['right_structure'];
$Structure = $data['score_structure'];
$benar_listening = $data['right_listening'];
$Listening = $data['score_listening'];
$finalscore = (($Listening + $Structure + $score)/3) * 10;
$NA = "INSERT INTO final_score VALUES ('$email', '$finalscore', '$Listening', '$Structure', '$score', '$right_listening', '$right_structure', '$right')";
if(mysql_query($query) && mysql_query($NA)){
header("location:index.php");
}else {
echo mysql_error();
}
}
?>
Aucun commentaire:
Enregistrer un commentaire