xxreenaxx1 Posted February 25, 2011 Share Posted February 25, 2011 Hey, I have checkbox and with these I am setting an exam. I want the questions to contain numbers. So for each question a number would be displayed. So far I am Only getting the question and the choices to display. <html> <?php session_start(); include '../Database/connection.php'; $Value22 = mysql_real_escape_string(trim($_POST['myselects'])); $_SESSION['myselect23'] = $Value22; //echo $_SESSION['myselect23']; ?> <body> <form action="Staff_Menu.php" method="post"> <?php include '../Database/previous_q.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/228857-how-to-add-numbers-on-a-checkbox/ Share on other sites More sharing options...
samshel Posted February 25, 2011 Share Posted February 25, 2011 <html> <?php session_start(); include '../Database/connection.php'; $Value22 = mysql_real_escape_string(trim($_POST['myselects'])); $_SESSION['myselect23'] = $Value22; //echo $_SESSION['myselect23']; ?> <body> <form action="Staff_Menu.php" method="post"> <?php include '../Database/previous_q.php'; $intNumber = 1; while($info = mysql_fetch_array( $sql )) { echo "[$intNumber] {$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $intNumber++; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/228857-how-to-add-numbers-on-a-checkbox/#findComment-1179791 Share on other sites More sharing options...
xxreenaxx1 Posted February 26, 2011 Author Share Posted February 26, 2011 Now that I have my choices. How do I display the checked checkbox according to the answer. My table contains Question Choice 1 Choice 2 Choice 3 Choice 4 Answer 1 Answer 2 Answer 3 Answer 4 If Answer 1 was a 0 then the checkbox shouldnt be ticked, and if it was a 1 then the text box should be ticked. I am NOT asking for the code can you just help me out. Direct me in the right direction and Ill get there. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/228857-how-to-add-numbers-on-a-checkbox/#findComment-1179803 Share on other sites More sharing options...
samshel Posted February 26, 2011 Share Posted February 26, 2011 Use the if else condition to check if the value os 0 or 1 and depending on that put the keyword "checked" <input type="checkbox" name=mybox value="1" checked> - This will show the checkbox as checked. Quote Link to comment https://forums.phpfreaks.com/topic/228857-how-to-add-numbers-on-a-checkbox/#findComment-1179807 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.