显示数据和单选按钮,并将单选按钮的选定值与数据一起保存

Show data and radio button and save selected value of radio button with data

本文关键字:数据 单选按钮 一起 保存 显示      更新时间:2023-09-26
嗨,有一个数据库,如下所示,数据正在

获取 来自PHP正在工作,但有问题需要显示针对所有学生名字的单选按钮,如下所示,并将数据发送回相应选择的单选按钮值的另一个表数据库。 在按钮上单击注册 ID 可用作存储在数据库中的主键。

数据库

 SchoolID   StudentRegID    StudentFirstName StudCourse   StudentSection 
    FT001     12KQC31085        ABC             BCOM             A
    FT001     12KQC31086        DEF             BCOM             A        
    FT001     12KQC31087        GHI             BCOM             A  
    FT001     12KQC31088        JKL             BCOM             A  

数据库

 SchoolID   StudentRegID    StudentFirstName StudCourse   StudentSection  Status
    FT001     12KQC31085        ABC             BCOM             A        Absent
    FT001     12KQC31086        DEF             BCOM             A        Leave        
    FT001     12KQC31087        GHI             BCOM             A        Absent  
    FT001     12KQC31088        JKL             BCOM             A        Present  

PHP 脚本

$mysqli=mysqli_connect('localhost','Uname','Pass','Database');
       //data from ajax
$standard1 = trim($_POST["tclass"]);
$section1 = trim($_POST["tsection"]);
$SchoolID1 = trim($_POST["tschoolid"]);
$query3="SELECT * FROM euser_student  WHERE  StudCourse='$standard1' and SchoolID='$SchoolID1'and StudentSection='$section1' order by StudentFirstName   ASC";
$data3=mysqli_query($mysqli,$query3)or die(mysqli_error());
while($row=mysqli_fetch_array($data3)){
    $dat3 = $row['StudentFirstName'];
    echo "<table><tr><td>"$dat3."</td></tr><table>";
}
  1. 期待出 看跌期权

                ABC         O Present   O Absent    O Leave
                DEF         O Present   O Absent    O Leave
                GHI         O Present   O Absent    O Leave
                JKL         O Present   O Absent    O Leave
    

3. 发送所选值

<table><tr><td>"$dat3."</td><td><input type="radio" name='si".$stydentregid."' value="Present">Present</td><td><input type="radio" name='si".$stydentregid."' value="Absent">Leave </td><td><input type="radio" name='si".$stydentregid."' value="Leave">Absent</td></tr><table> 创建表列时创建上面。 提交时获取单选按钮列表的值。

我不是PHP开发人员,但我可以给你存储数据的逻辑你可以像这样生成表格html

 <table>
    <tr>
         <td>student Name</td>
          <td><input type="radio" value="p" id="StudentRegID_P" name="StudentRegID"><label for="StudentRegID_P" >Present<label/></td>
          <td><input type="radio" value="a" id="StudentRegID_A" name="StudentRegID"><label for="StudentRegID_A" >Absent<label/></td>
          <td><input type="radio" value="l" id="StudentRegID_L" name="StudentRegID"><label for="StudentRegID_P" >Leave<label/></td>
    </tr>
 <table>

其中"学生注册ID"是您从数据库中的实际学校注册ID。

因此,当用户选择"选择和

回发数据"时,您将在"请求表单"中选择"以学生注册ID作为键的用户"和"选择"作为值的用户。

我可以告诉您如何使用复选框来实现这一点,就像您可以使用单选按钮一样。

您可以将输入标签如下添加到显示数据的 php 页面

echo "<input id="students_" name="students[]" type="radio" value="**UniqueID**"><table><tr><td>"$dat3."</td></tr><table>";

然后在您的另一个 php 文件中,您有代码来检查提交的学生,添加以下内容

$students = $_REQUEST['students'];
foreach ($gextras as $val) 
{
//Do the database code here
}