<?php
$myResult = 0;
$myTest = 0;
$connection = pg_connect("dbname=ab user=ac host=localhost");
$query = "select * from questions where ggroup=1 and type=0";
$result = pg_query($connection, $query);
while ($row = pg_fetch_array($result)) {
get ALL radio questions from database
$question = 'q'.$row[0];
$myAnswer = 0;
if(isset($POST[$question])) {
$query="select from answers where question=".$row[0]." and correct='1'";
$result = pg_query($connection, $query);
$row = pg_fetch_array($result);
if($POST[$question] == $row['answer']) {
$myAnswer = 4;
} else {
$myAnswer = -1;
}
$myTest += $myAnswer;
}
}
$query = "select from questions where ggroup=1 and type=1";
$result = pg_query($connection, $query);
while ($row = pg_fetch_array($result)) {
get ALL checkboxes questions from database
$myAnswer = 0;
$myAnswer = array();
$query = "select * from answers where question=".$row[0]."";
$result = pg_query($connection, $query);
$counter = 0;
while($row = pg_fetch_array($result)) {
$question = 'q'.$row[0].''.$row[0];
if(isset($POST[$question])) {
if($POST[$question] == 'ok' && $row['correct'] == '1') {
$myAnswer[$counter] = 1;
} else if ($POST[$question] != 'ok' && $row['correct'] == '1') {
$myAnswer[$counter] = -1;
} else if ($POST[$question] == 'ok' && $row['correct'] == '0') {
$myAnswer[$counter] = -1;
} else {
$myAnswer[$counter] = 1;
}
}
$counter++;
}
$myAnswer = 4;
for($i=0; $i<4; $i++) {
if($myAnswer[$i] == -1) {
//if($_myAnswer[$i] == -1) {
$myAnswer = -1;
}
}
$myTest += $myAnswer;
}
print $myTest.'/48';
?>
for one correct ans im diaplying radio button
for more than one correct ans im displaying checkbox
correct and +4
wrong ans -1
total no of ques 12...max score 48..min -12.
now in my code when i slect all the right ans from it give 48 score
when i select wrong option from radio button question it gives me correct score but when i select wrong option from checkboxes it is not showing me the correct score
Table "public.answers"
Column | Type | Modifiers
----------+---------+------------------------------------------
answer | integer | not null default nextval('serial'::text)
question | integer | not null default 0
text | text | not null
correct | boolean | not null default false
note | text | not null
Table "public.questions"
Column | Type | Modifiers
----------+---------+------------------------------------------
id | integer | not null default nextval('serial'::text)
question | text | not null
ggroup | integer | not null default 0
used | integer | not null default 0
note | text | not null
type | integer | not null default 0