I am creating a survey that asks the user questions in order to determine what Majors would be most appropriate for that user based on their answers. I want to display the questions one at a time. The user should be able to press the next button and the next question stored in the database will appear on the screen. Right now I have my code working to where it displays the first question from the database, but I still need to get the next button working. I need an efficient way to do this since I have 60 questions stored in the database. Any help is greatly appreciated! Below is a picture of how my survey currently looks!
Below is my code!
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "Cherries7";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$id = 1; //global variable that represents id
$sql = "SELECT questiontext FROM md WHERE ID= '$id'" ;
mysql_select_db('MajorDecider');
$retval = mysql_query( $sql, $conn );
$nr = mysql_num_rows($retval);
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
else if($nr == 0) {
echo "<h2>Question not found.</h2>";
}
//there should only be one question with specified id number
else if($nr == 1) {
$row = mysql_fetch_array($retval);
echo " <form method='POST'>
<section id='question'><table id='questions'>
<tr>
<td> {$row['questiontext']} </td>
<td> <input type='radio' name='choose' id='interested' value='true' /> Yes </td>
<td> <input type='radio' name='choose' id='uninterested' value='false' /> No </td>
<td> <button name='next'>Next</button> </td>
</tr>
</table></section></form> ";
}