while loop with radio buttons
Posted: Fri Nov 21, 2008 4:18 pm
hi,
Can any one help me. I am facing problem with the radio button using while loop. i need to to select the choice for any number of questions displayed on the screen and insert the selected values to the table. currently I am able to select choice for only 1 question with the coding given below. As i am new to PHP can anyone help me.
Thanks
sreem
<html>
<head>
<title>PHP</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
<body>
<?
require "config.php"; // user passwd dbname
$limit = 20; // No of records selected
$counter = 1;
$query2=" SELECT * FROM exam_ques ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
?>
<table align=center border=1 width=80% height=150>
<tr>
<td width=100% id=ex align=center colspan=9>Module : <? echo $info['module_no']; ?> </td>
</tr>
<?
$query=" SELECT * FROM exam_ques limit $limit ";
$result=mysql_query($query);
$totalrow=mysql_num_rows($result);
echo mysql_error();
$i=1;
{
while($info = mysql_fetch_array( $result ))
{
{
?>
<tr>
<td colspan=9><br>
</td>
</tr>
<tr>
<td width=5% id=ex>Question :<? echo $counter++; ?></td>
<td colspan=9 width=100%> <font size="5"><? echo $info['question']; ?></font></td>
</tr>
<tr>
<td colspan=9><br>
</td>
</tr>
<td align=center colspan=9 id=ex>Choices</td>
</tr>
<form name="thisForm" action="insert_answers_to_table.php" method="post">
<?
?>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_1']; ?>" name="radio1"><? echo $info['choice_1']; ?><br></td>
</tr>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_2']; ?>" name="radio1" ><? echo $info['choice_2']; ?><br></td>
</tr>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_3']; ?>" name="radio1" ><? echo $info['choice_3']; ?><br></td>
</tr>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_4']; ?>" name="radio1"><? echo $info['choice_4']; ?><br></td>
</tr>
<?
}
}
}
?>
</table>
<table border=0 width=80% align="center">
<tr>
<td align="center">
<input id="ex" type="submit" name="submit" value="Submit" action="insert_answers_to_table.php">
</form>
</td>
</tr>
</table>
</body>
</html>
Can any one help me. I am facing problem with the radio button using while loop. i need to to select the choice for any number of questions displayed on the screen and insert the selected values to the table. currently I am able to select choice for only 1 question with the coding given below. As i am new to PHP can anyone help me.
Thanks
sreem
<html>
<head>
<title>PHP</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
<body>
<?
require "config.php"; // user passwd dbname
$limit = 20; // No of records selected
$counter = 1;
$query2=" SELECT * FROM exam_ques ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
?>
<table align=center border=1 width=80% height=150>
<tr>
<td width=100% id=ex align=center colspan=9>Module : <? echo $info['module_no']; ?> </td>
</tr>
<?
$query=" SELECT * FROM exam_ques limit $limit ";
$result=mysql_query($query);
$totalrow=mysql_num_rows($result);
echo mysql_error();
$i=1;
{
while($info = mysql_fetch_array( $result ))
{
{
?>
<tr>
<td colspan=9><br>
</td>
</tr>
<tr>
<td width=5% id=ex>Question :<? echo $counter++; ?></td>
<td colspan=9 width=100%> <font size="5"><? echo $info['question']; ?></font></td>
</tr>
<tr>
<td colspan=9><br>
</td>
</tr>
<td align=center colspan=9 id=ex>Choices</td>
</tr>
<form name="thisForm" action="insert_answers_to_table.php" method="post">
<?
?>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_1']; ?>" name="radio1"><? echo $info['choice_1']; ?><br></td>
</tr>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_2']; ?>" name="radio1" ><? echo $info['choice_2']; ?><br></td>
</tr>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_3']; ?>" name="radio1" ><? echo $info['choice_3']; ?><br></td>
</tr>
<tr><td width=5%> </td>
<td colspan=9 width=500><input type="radio" value="<? echo $info['choice_4']; ?>" name="radio1"><? echo $info['choice_4']; ?><br></td>
</tr>
<?
}
}
}
?>
</table>
<table border=0 width=80% align="center">
<tr>
<td align="center">
<input id="ex" type="submit" name="submit" value="Submit" action="insert_answers_to_table.php">
</form>
</td>
</tr>
</table>
</body>
</html>