获取整行单选值的值到下一个文件


Get values of radio selected values of entire row to next file

我已经显示了mysql表的值以及具有不同值的单选按钮。在提交按钮上,它应该重定向到下一页并显示所选值。我在第一个文件上的代码如下:

$query1 = "select * from booking";
$result1 = $connection->query($query1);
echo "<form method='post' action='edit.php'>";
echo "<center>";
echo "<table border='1'>";
$count = 0;
while($row = $result1->fetch_row())
{
    echo "<tr>";
    echo "<td width=".'10'.">";
    $count = $count + 1;
    #$sr=$sr+1;
    echo "<input type='radio' name='select' value='".$count."' />";
    #$row = mysqli_fetch_row($result1);
    #echo "<tr>";
    echo "<td width=".'10'.">";
    $rooms = $row[0];
    $srrooms = $rooms;
    echo "<input type='text' name='srrooms' value='".$srrooms."'     hidden='hidden'>";
    #echo $srrooms;
    echo $rooms;
    echo "</td>";
    echo "<td width=".'10'.">";
    $no_roomss = $row[1];
    $nosrrooms = $no_roomss;
    echo "<input type='text' name='nosrrooms' value='".$nosrrooms."' hidden='hidden'>";
    echo $no_roomss;
    echo "</td>";
    echo "<td width=".'10'.">";
    $no_dayss = $row[2];
    $nodays = $no_dayss;
    echo "<input type='text' name='nodays' value='".$nodays."' hidden='hidden'>";
    echo $no_dayss;
    echo "</td>";
    echo "<td width=".'10'.">";
    $name = $row[3];
    echo $name;
    echo "</td>";
    echo "</tr>";
    #$count++;
}
echo "<input name='count' type='hidden' id='count'>"; // hidden input where     counter value will be stored
echo "</table>";
echo "<input type='submit' name='submitRooms' />";
echo "</center>";
echo "</form>";

javascript代码如下:$(函数(){$("输入[name = "选择"]").change(函数(){$(" #计数").val($("输入[name = '选择']:检查").val ());});});

edit.php代码为:

<?php
if(isset($_POST['submitRooms'])){
    @$count = $_POST['count'];
    @$srrooms=$_POST['srrooms'.$count];
    @$nosrrooms=$_POST['nosrrooms'.$count];
    @$nodays=$_POST['nodays'.$count];
    echo 'Selected values are: '. $srrooms . $nosrrooms . $nodays;
}
?>

您可以使用counter来提交所选单选按钮行的值:

<?php 
$query1 = "select * from booking";
$result1 = $connection->query($query1);
echo "<form method='post' action='edit.php'>";
echo "<center>";
echo "<table border='1'>";
$count = 0; // counter variable
while($row = $result1->fetch_row())
{
    echo "<tr>";
    echo "<td width=".'10'.">";
    echo "<input type='radio' name='select' value='".$count."' />";
    echo "<td width=".'10'.">";
    $rooms = $row[0];
    $srrooms = $rooms;
    echo "<input type='hidden' name='srrooms".$count."' value='".$srrooms."' >"; // add counter value to every name of the input fields
    echo $rooms;
    echo "</td>";
    echo "<td width=".'10'.">";
    $no_roomss = $row[1];
    $nosrrooms = $no_roomss;
    echo "<input type='hidden' name='nosrrooms".$count."' value='".$nosrrooms."'>";
    echo $no_roomss;
    echo "</td>";
    echo "<td width=".'10'.">";
    $no_dayss = $row[2];
    $nodays = $no_dayss;
    echo "<input type='hidden' name='nodays".$count."' value='".$nodays."' >";
    echo $no_dayss;
    echo "</td>";
    echo "<td width=".'10'.">";
    $name = $row[3];
    echo $name;
    echo "</td>";
    echo "</tr>";
    $count++;
}
echo "<input name='count' type='hidden' id='count'>"; // hidden input where counter value will be stored
echo "</table>";
echo "<input type='submit' name='submitRooms' />";
echo "</center>";
echo "</form>";
?>

,然后使用jquery在隐藏计数输入字段中保存活动单选按钮计数[在上述PHP代码之后]

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type='text/javascript'>
$(function(){
    $('input[name="select"]').change(function(){
        $('#count').val($("input[name='select']:checked").val());
    });
});
</script>

然后在您的edit.php中获取发布的数据:

<?php
if(isset($_POST['submitRooms'])){
    @$count = $_POST['count'];
    @$srrooms = $_POST['srrooms'.$count];
    @$nosrrooms = $_POST['nosrrooms'.$count];
    @$nodays = $_POST['nodays'.$count];
    echo 'Selected values are: '. $srrooms . $nosrrooms . $nodays;
}
?>

你没有添加整个表单代码,所以请添加上面提到的表单代码,你的代码不工作的原因是你没有添加输入字段名称的计数。如果输入字段没有$count变量

就不能在edit。php中使用count获取发布数据
echo "<input type='hidden' name='srrooms".$count."' value='".$srrooms."' >";