dongzhiyan5693 2019-07-29 02:14
浏览 101

将选定的dataTable行传递给另一个php页面中的另一个dataTable行

I have these two tables, namely table1.php and table2.php

I can pass the data to a modal using this script, this script is in table1.php, and it can pass data into table2.php via modal, my concern now is how will I pass the data directly into table2.php's SQL Query? Because of the way that it is, I can only use the data passed into a modal for HTML elements. Is there a way to pass the modal value and convert it into a SQL Query for PHP?

$(function(){
  $("body").on('click', '.edit', function (e){
    e.preventDefault();
    $('#edit').modal('show');
    var id = $(this).data('id');
    getRow(id);
  });

I'm trying to pass the selected data row into another PHP page so that it will become the parameter for filtering the second PHP table.

This is my table1.php

<form type="POST" action="table2.php">
              <table id="example1" class="table table-bordered">
                <thead>
                  <th>Series No.</th>
                  <th>Account Type</th>
                  <th>Tools</th>
                </thead>
                <tbody>
                  <?php
                    $sql = "SELECT * FROM accounttype";
                    $query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
                    while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
                      echo "
                        <tr>
                        <td>".$row['seriesno']."</td>
                          <td>".$row['accounttype']."</td>
                          <td>
                            <button class='btn btn-success btn-sm edit btn-flat' data-id='".$row['seriesno']."'><i class='fa fa-edit'></i> Edit</button>
                            <button class='btn btn-danger btn-sm delete btn-flat' data-id='".$row['seriesno']."'><i class='fa fa-trash'></i> Delete</button>
                          </td>
                        </tr>
                      ";
                    }
                  ?>
                </tbody>
              </table>
              </form>

And this will be my table2.php

<table id="example2" class="table table-bordered">
                <thead>
                  <th>Series No.</th>
                  <th>Account Type</th>
                </thead>
                <tbody>
                  <?php
                    $id=$_POST['seriesno'];
                    $sql = "SELECT * FROM accounttype where seriesno='$id'";
                    $query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
                    while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
                      echo "
                        <tr>
                        <td>".$row['seriesno']."</td>
                          <td>".$row['accounttype']."</td>
                        </tr>
                      ";
                    }
                  ?>
                </tbody>
              </table>

The problem is that table2.php cannot receive the $_POST, what seems to be the problem here?

EDIT: This is my modal (table2.php) What I need is for the data to be passed into the table so that $id=$_POST['seriesno']; will work.

<div class="modal fade" id="edit">
    <div class="modal-dialog" style="width:100%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                    <input type="hidden" class="decid" id="id" name="id">

  <table id="example2" class="table table-bordered">
                <thead>
                  <th>Series No.</th>
                  <th>Account Type</th>
                </thead>
                <tbody>
                  <?php
                    $id=$_POST['seriesno'];
                    $sql = "SELECT * FROM accounttype where seriesno='$id'";
                    $query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
                    while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
                      echo "
                        <tr>
                        <td>".$row['seriesno']."</td>
                          <td>".$row['accounttype']."</td>
                        </tr>
                      ";
                    }
                  ?>
                </tbody>
              </table>
            </div>
        </div>
    </div>
</div>
  • 写回答

1条回答 默认 最新

  • dpw70180 2019-07-29 02:51
    关注

    So.. the problem is that you have to submit on the same page: and parse the $_POST array in modal window in the same page because it it included here. Try this:

    table1.php:

    <form method="POST" action="table1.php">
              <table id="example1" class="table table-bordered">
                <thead>
                  <th>Series No.</th>
                  <th>Account Type</th>
                  <th>Tools</th>
                </thead>
                <tbody>
                  <?php
                    $sql = "SELECT * FROM accounttype";
                    $query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
                    while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
                      echo "
                        <tr>
                        <td>".$row['seriesno']."</td>
                          <td>".$row['accounttype']."</td>
                          <td>
                            <button class='btn btn-success btn-sm edit btn-flat' data-id='".$row['seriesno']."'><i class='fa fa-edit'></i> Edit</button>
                            <button class='btn btn-danger btn-sm delete btn-flat' data-id='".$row['seriesno']."'><i class='fa fa-trash'></i> Delete</button>
                          </td>
                        </tr>
                      ";
                    }
                  ?>
                </tbody>
              </table>
              </form>
    

    table2.php

    <div class="modal fade" id="edit">
        <div class="modal-dialog" style="width:100%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                        <input type="hidden" class="decid" id="id" name="id">
    
      <table id="example2" class="table table-bordered">
                    <thead>
                      <th>Series No.</th>
                      <th>Account Type</th>
                    </thead>
                    <tbody>
                      <?php
                        if(isset($_POST['seriesno'])){
                        $id=$_POST['seriesno'];
                        $sql = "SELECT * FROM accounttype where seriesno='$id'";
                        $query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
                        while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
                          echo "
                            <tr>
                            <td>".$row['seriesno']."</td>
                              <td>".$row['accounttype']."</td>
                            </tr>
                          ";
                        }
                        }
    
                      ?>
                    </tbody>
                  </table>
                </div>
            </div>
        </div>
    </div>
    

    Hope it heps

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器