我想在获取的记录中获取单选按钮的选定值的值..我没有得到单选按钮值...告诉我它是对还是错..在这种情况下它是动态的...如果它是静态没有问题..但这是动态的..如何做到这一点..?或任何其他方式......任何帮助都会很明显..
<?php
while($res = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>". "<input type='radio' name= 'Returns'
value=".$res['T_no'].")>". "</td>";
echo "<td>".$res['T_no']."</td>";
?>
<form action="sample.php" method="POST" class="form-inline">
<input type="submit" value="Get Sch"/>
</form>
sample.php
<?php
$con = mysql_connect("localhost", "root", "");
if ($con) {
$db = mysql_select_db('tdb', $con);
} else {
die('Could not connect: ' . mysql_error());
}
echo "you have selected :".$_POST['Returns']; // Displaying Selected Value
echo $POST['Returns'];
$selected_val = $_POST['Returns']; // Storing Selected Value In Variable
echo "You have selected :" .$selected_val; // Displaying Selected Value
$result = mysql_query("SELECT * FROM t_detail WHERE
T_No='$selected_val'");
mysql_close($con)
?>
答案 0 :(得分:0)
在您使用$_POST['Returns[]']
的代码中,它应该是$_POST['Returns']
。因为这是一个数组,所以您可以implode
或使用foreach
获取每个单选按钮值
您可以执行以下操作:
<form action="schedule.php" method="POST" class="form-inline">
<?php
while($res = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>". "<input type='radio' name= 'Returns'
value=".$res['Train_no'].")>". "</td>";
echo "<td>".$res['Train_no']."</td>";
?>
<input type="submit" value="Get Schedule"/>
</form>
==============
$implode = implode(',',$selected_val);
$result = mysql_query("SELECT * FROM train_detail WHERE
Train_No='".$implode."'");