I have a problem in my logic. I have a table which has 10 col. Those 10 col contains 8 col of different question. Each questions is answered by yes and no and each ROW questions have been answered differently(Please look at the table below).I want to calculate marks for One particular row at a time But for some reason when I fetch value I have different title and description of rows but same marks for each rows(Please see the output below).And I am getting 4.5 marks for each row. All I wanted is separate marks for different rows.
The value of YES IS 1 The value of NO IS 0. and I am multiplying those values with my marking scheme.
I am calculating the value with the help of this code:
<!DOCTYPE html>
<?php
include 'common.php';
$command = "SELECT Title, Description, Question1, Question2, Question3, Question4, Question5, Question6, Question7, Question8 FROM sachjot";
// prepare and executing
$stmt = $dbh->prepare($command);
$result = $stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); // get all result using this
$p; // variable to store all the values of different questions per row
foreach($results as $data){
$data['Question1'];
$data['Question2'];
$data['Question3'];
$data['Question4'];
$data['Question5'];
$data['Question6'];
$data['Question7'];
$data['Question8'];
if ($data['Question1'] == "YES"){
$p += 1 * 1; // 1 is the marking scheme marks
}else{
$p = 0 * 1;
}
if ($data['Question2'] == "YES"){
$p += + 1 * 0.5; // 0.5 is the marking scheme marks
}else{
$p += 0 * 0.5;
}
if($data['Question3'] == "YES"){
$p += 1 * 2; // 2 is the marking scheme marks
}else{
$p += 0 *2;
}
if($data['Question4'] == "YES"){
$p += 1*1;
}else{
$p += 0 * 1;
}
if($data['Question5'] == "YES"){
$p += 1 *1.5;
}else{
$p += 0 * 1.5;
}
if($data['Question6'] == "YES"){
$p += 1 * 1;
}else{
$p += 0 * 1;
}
if($data['Question7'] == "YES"){
$p += 1 * 1;
}else{
$p += 0 *1;
}
if($data['Question8'] === "YES"){
$p += 1 * 2;
}else{
$p += 0*2;
}
}
?>
And fetching them with the help of this code:
<?php
foreach($results as $row){
// echo "<tr><td>".$row["rank"]."</td>";
echo "<tr><td>".$row['Title']."</td>";
echo "<td>".$p."</td>";
echo "<td>".$row['Description']."</td></tr>";
}
?>