Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用复选框显示数据库,并将所选数据查询到另一个php文件中_Php_Jquery_Sql_Checkbox - Fatal编程技术网

使用复选框显示数据库,并将所选数据查询到另一个php文件中

使用复选框显示数据库,并将所选数据查询到另一个php文件中,php,jquery,sql,checkbox,Php,Jquery,Sql,Checkbox,我只想在表中显示我的数据库,并且在表中的每一行都有一个复选框。用户可以选择选中一个或多个框,然后点击提交按钮,在另一个页面中查看所选数据。 下面是我尝试的代码 index.php <!--Adds column titles --> <div style="overflow-x:auto;"> <table id="test_data"> <tr>

我只想在表中显示我的数据库,并且在表中的每一行都有一个复选框。用户可以选择选中一个或多个框,然后点击提交按钮,在另一个页面中查看所选数据。 下面是我尝试的代码

index.php

<!--Adds column titles -->
      <div style="overflow-x:auto;">
         <table id="test_data">
           <tr>
             <th> Select </th>
             <th> Test ID </th>
             <th> Path </th>
             <th> Video 1 Path </th>
             <th> Video 2 Path</th>
             <th> Video 3 Path</th>
             <th> Video 4 Path</th>
           </tr>

           <!--Prints out data from test_data table-->
           <?php
             $sql = "SELECT * FROM test_data";
             $result= mysqli_query($conn, $sql);
             $queryResults = mysqli_num_rows($result);



               if ($queryResults > 0) {
                 echo "<form action= 'search.php' method='get'>";
                 while ($row = mysqli_fetch_assoc($result)) {
                   echo "<tr>
                           <td><input type='checkbox' name='checkbox_id' value='" . $test_id . "'> </td>
                           <td> ".$row['test_id']." </td>
                           <td> ".$row['path']." </td>
                           <td> ".$row['video1_path']." </td>
                           <td> ".$row['video2_path']." </td>
                           <td> ".$row['video3_path']." </td>
                           <td> ".$row['video4_path']." </td>
                         </tr>";



                 }
                echo "<input type= 'submit' value='submit' >";
               echo "</form>";
               }
           ?>

         </table>
       </div>

挑选
测试ID
路径
视频1路径
视频2路径
视频3路径
视频4路径

您的复选框值现在是“$Test_id.”,但不是真实的id,请更正复选框中的值,不要完全得到您的响应。你能再解释一下吗?试着在浏览器中显示复选框的值,你就会明白你的错误是什么,我改变了value='checkbox\u id',但还是没有运气。我还想补充一点:我在浏览器中没有发现任何错误。我在sql查询中发现了一个错误,您没有这样一个变量:$checkbox\u id在sql查询中。您可以解释我下一步应该做什么。我是PHP新手。谢谢
<div style="overflow-x:auto;">
          <table id="test_data">
            <tr>
              <th> Test ID </th>
              <th> Path </th>
              <th> Video 1 Path </th>
              <th> Video 2 Path</th>
              <th> Video 3 Path</th>
              <th> Video 4 Path</th>
            </tr>


            <?php
              if (isset($_POST['checkbox_id'])) {
                $checkbox_id = $_POST['checkbox_id'];
                $sql= "SELECT * FROM test_data WHERE test_id IN $checkbox_id";
                $result = mysqli_query($conn, $sql);
                $queryResults = mysqli_num_rows($result);

                
                if ($queryResults > 0) {
                  while ($row = mysqli_fetch_assoc($result)){
                    $field1name = $row["test_id"];
                    $field2name = $row["path"];
                    $field3name = $row["video1_path"];
                    $field4name = $row["video2_path"];
                    $field5name = $row["video3_path"];
                    $field6name = $row["video4_path"];

                    echo "<tr>
                            <td> ".$field1name." </td>
                            <td> ".$field2name." </td>
                            <td> ".$field3name." </td>
                            <td> ".$field4name." </td>
                            <td> ".$field5name." </td>
                            <td> ".$field6name." </td>
                          </tr>";
                  }
                }else {
                  echo "There are no results matching your search";
                }
              }

            ?>
          </table>
        </div>