此代码从数据库中获取一些数据,并使用一组单选按钮显示它。如何获取每组单选按钮的值?
<form name="functional" method="post" action="funcsub.php">
<?php
$n=0;
$con=mysqli_connect('localhost','Sanjana','sanjana');
mysqli_select_db($con,'mydatabase');
$sql = mysqli_query($con,"select * from functional") or die("Failed");
while($result = mysqli_fetch_array($sql)){
?>
<br/>
<?php
echo $result["Skill"];
echo "</br>";
echo"<input type='radio' name='tech[.$n.]' value='0'>0";
echo"<input type='radio' name='tech[.$n.]' value='1'>1";
echo"<input type='radio' name='tech[.$n.]' value='2'>2";
echo"<input type='radio' name='tech[.$n.]' value='3'>3";
echo"<input type='radio' name='tech[.$n.]' value='4'>4";
echo"<input type='radio' name='tech[.$n.]' value='5'>5";
$n=$n+1;
}
?>
<br/>
<input type="submit" name="submit" value="Submit">
</form>
答案 0 :(得分:1)
这些中不需要这些点。也许你的意思是?:
echo "<input type='radio' name='tech[".$n."]' value='0'>0";
echo "<input type='radio' name='tech[".$n."]' value='1'>1";
echo "<input type='radio' name='tech[".$n."]' value='2'>2";
echo "<input type='radio' name='tech[".$n."]' value='3'>3";
echo "<input type='radio' name='tech[".$n."]' value='4'>4";
echo "<input type='radio' name='tech[".$n."]' value='5'>5";
假设这是你想要的,你可以得到这样的价值(我更喜欢在印刷部分(或你的表格,在这种情况下)上面写字):
if (!empty($_POST)) {
$tech = $_POST['tech'];
echo 'Value of the second row: '.$tech[1];
}