Jump to content

How to add numbers on a checkbox


xxreenaxx1

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/228857-how-to-add-numbers-on-a-checkbox/
Share on other sites

<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>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.