If I am in wrong spot please advise
My problem, NEW TO php AND I HAVE BEEN READING THAT THIS LOOPING IS EASY. One full month, I didn't want to take up your time. At a confused point. Cannot find the key to understanding this. I worked this to NO ERROR MESSAGES. Still failing purpose.
Code will print out all in the questions $row in the array into browser for all $row or just one; instead of looping through once and allowing next question to be read and responded to via radio button.
For example, I would like to cycle through 60 multiple choice questions, one at a time, using a radio button to send responce A, B, C, D. via "submit" the submit part is working connecting to database to get different tables is working, see below. Controlling question output at just one at a time with not moving to next
row in $row = mysql_fetch_array($result); OR prints out all question sets , 8 available, 5 printed, but still not separating question submit. click any radio button and all questions are answered the same.
/ Program: multiple_choice_test in PHP
Desc: FILE: mct-2.php ...Is an an atempt to
generate multiple choice questions- "one at a time" -
to be answered with a radio button responce, with submit button taking
information to be processed and compared to an answer data base, . Both Radio button and Answer from qTwoAn_tbl are compared printed, wrong answer to be
INSERT INTO missedAn_tbl ... , print $RadioAn and $correct to page.
this query INSERT INTO does not work it kills just question print out...blank
$query = mysql_query("INSERT INTO setTwoMiss_tbl (questionID,missedQ2)
VALUES ('$questionID','$RadioAn')") or die("Couldn't execute insert query");
:::::::::::Copy of page print out :::: after A was choosen and submit clicked :::: coded to limit to one question with a do_while code, but no updating to new question can I figure.
0 : counter
You selected the qTwo_tbl NAV test.
Has db tbl rows.
row count number 14-------------------- do you know why this is 14? There are 8 sample questions total
For Question #: 2. You selected A
Correct answer from qTwoAn_tbl: A
Question number: 2
Below is the NEXT QUESTION
Master Exam Prep
#.3. A stopper used in securing the ground tackle for sea that consists of a grab attached to a turnbuckle is a:
A. riding pawl
B. buckler
C. devil's claw
D. locking ring
A. B. C. D.
Submit
2
***************************************************************** START OF PAGE CODE **************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Cycle through multiple_choice_test in php file - qTwo_tbl questions</title>
</head>
<body>
<?php
$submitted = 'no';
$user = 'root';
$password = 'vahamaki';
$host = 'localhost';
$port = '3306';
$server = 'localhost';
$database = 'mep_db';
//$query = 'show databases';
//$query = 'SELECT * FROM qTwo_tbl';
//mysql_connect("localhost", "root", "vahamaki") or die(mysql_error());
$link = mysql_connect ($server, $user, $password) or die(mysql_error());
if (!link)
{
die('ERROR: Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected)
{
// do_close($link);
die('ERROR: Could not select database: ' . $database . ': error = ' . mysql_error());
}
$result = mysql_query("SELECT * FROM qTwo_tbl");
// $result = mysql_query($query, $link);
if (!$result)
{
$message = 'ERROR: ' . mysql_error();
die($message);
}
$row = mysql_fetch_array($result);
$count = count($row);
$counter = 0;
/* This prints all questions . submit shows same answer at each, 5 questions
$start = 0;
for($start; $start < 2; $start++)
{
$counter = $counter++;
*/
print $counter . "<BR>";
//$i = 0;
if ($count < 5)
{
$i = 0;
}
// next($row);
do {
// echo $i; worked before
// mysql_free_result($result);
// do_close($link);
//for ($i = $start; $i <= $end; $i++)
//$interest = $_REQUEST["interest"];
echo " <H4> You selected the qTwo_tbl NAV test. </H4>";
if (!$row )
{
echo "could not get row information. ";
}
if ($row)
{
echo "Has db tbl rows. <BR />" ;//This worked;
}
echo " row count number ".$count;//This worked
$RadioAn = $_REQUEST["RadioAn"];
// echo " You selected <b>".$RadioAn."</b>";
echo "<BR>For Question #: </b>".$row['questionID']. ". You selected <b>".$RadioAn."</b>";
//$RadioAn = $_REQUEST["RadioAn"];
//echo " You selected <b>".$RadioAn."</b>";
// retieve and store the records of the "qTwoAn_tbl" table into $result2 -> $rowan
$result2 = mysql_query("SELECT * FROM qTwoAn_tbl")
// if no connect to table "qTwoAn_tbl" die
or die("Couldn't execute SELECT query");
$rowan = mysql_fetch_array( $result2 );
echo " <BR> Correct answer from qTwoAn_tbl: <b>".$rowan['correct']."</b>";
echo "<BR>";
echo "Question number: <b>".$row['questionID']."</b><br>";//This worked
//Compare answer with correct answer
//**** ADD IN HERE a NEXT array pointer ****
/if
($Radio1 == $rowan['correct']);
{ echo "Great. You chose the correct answer";
}
$query = mysql_query("INSERT INTO setTwoMiss_tbl (questionID,missedQ2)
VALUES ('$questionID','$RadioAn')") or die("Couldn't execute insert query");
echo "WRONG answer: <b>".$RadioAn."</b>";
*/
/* while ($iterator -> valid($row))
{
$row = $iterator->current() ;
}
//START Process $element
*/
echo "<br /> <br />Below is the    NEXT QUESTION <br />";
$result3 = mysql_query("SELECT * FROM qTwo_tbl")
or die("Couldn't execute SELECT query");
$row = mysql_fetch_array( $result );
//echo $row["questionID"];
echo "<center><h3>Master Exam Prep</h3></center>\n";
// Question Print Starts Here
{
print "<table >";
echo "<tr><td>#.";
echo $row["questionID"];
echo ".</td><td>   </td><td>";
echo $row["question"];
echo "<BR>\n";
echo "</tr>";
echo "<tr><td>A.";
echo "</td><td>   </td><td>";
echo $row["A"];
echo "</td><td>   </td><td>";
echo "<BR></tr>\n";
echo "<tr><td>B.</td>";
echo "<td>   </td><td>";
echo $row["B"];
echo "</td><td>";
echo "<BR></tr>\n";
echo "<tr><td>C.";
echo "</td><td>   </td><td>";
echo $row["C"];
echo "</tr>\n";
echo "<BR>";
echo "<tr><td>D.</td>";
echo "<td>  </td><td>";
echo $row["D"];
echo "</td></tr>";
echo "</table>";
echo "<BR>";
}
//END question Print Table
echo "<CENTER>";
echo "<br /><br /><br />";
echo "
<FORM METHOD=\"POST\" ACTION=\"$_POST_self\">.
<Input NAME=\"RadioAn\" TYPE=\"RADIO\" VALUE=\"A\">A.
<Input NAME=\"RadioAn\" TYPE=\"RADIO\" VALUE=\"B\">B.
<Input NAME=\"RadioAn\" TYPE=\"RADIO\" VALUE=\"C\">C.
<Input NAME=\"RadioAn\" TYPE=\"RADIO\" VALUE=\"D\">D.";
echo "<BR><BR>";
echo "<INPUT TYPE=\"SUBMIT\" VALUE=\"SUBMIT\"><BR></FORM>";
echo "</CENTER>";
echo current($row) . ' ';
//next($row);
//$i = $i + 1;
}
while ($i > 0);
?>
</body>
</html>
*********************************************END OF PAGE CODE **************
Any help would be appreciated. Thanks