good day!
Please help me here, I need to count the record according to my condition but with my code it only counts the last record in the table in MySql. Here is my code.. Thanks!
<?php
//establishing connection
mysql_connect("localhost", "abc", "bbb") or die(mysql_error());
$submit = $_POST['submit'];
$cancel = $_POST['cancel'];
$answer = $_POST['answer'];
//connecting to the database
mysql_select_db("xxx") or die(mysql_error());
$result = mysql_query("SELECT * FROM qqq") or die(mysql_error());
echo "<center><font size=2 face=Arial><b>qwerty</b></font></center><br/>";
echo "<font size=1 face=Arial><b>Type in True if the statement is correct and False if otherwise.</b></font><br/><br/>";
echo "<table cellpadding = 1><tr><th><font size = 1>Answer</th><th><font size = 1>Question</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr><td>";
echo "<font size = 1><input name='answer' type='text'>";
echo "</font></td><td><font size = 1>";
$question = $row['question'];
$answer = $row['answer'];
$id = $row['questionid'];
echo $question;
echo "</td></tr>";
}
echo "</table>";
echo "</font></center>";
if ($cancel == 'Cancel')
{
echo "<META HTTP-EQUIV=REFRESH CONTENT='0; URL=http://abc/qwerty/adggd/dgdg.php'>";
exit;
}
else if ($submit == 'Submit')
{
$date = date("F d, Y");
$count = mysql_query("SELECT COUNT(*) FROM qqq WHERE question = '$question' && answer = '$answer' && questionid = '$id'") or die(mysql_error());
$score = mysql_result($count,0,0);
mysql_query("INSERT INTO results (idnumber, fullname, score, exam_title, exam_dept, exam_date)
VALUES ('$pangalanUser','$fullname', '$score','Awareness and Reminders', 'ECM Production', '$date')")
or die(mysql_error());
echo "<script>alert('Your score is $score! Score is already saved.')</script>";
echo "<META HTTP-EQUIV=REFRESH CONTENT='0; URL=http://abc/qwerty/adggd/dgdg.php'>";
}
?>