首页 > 解决方案 > PHP MYSQL将相同的数据从表显示到另一个页面

问题描述

<div class="card-header py-3">
          <h4 class="m-2 font-weight-bold text-primary">Asset Approval List</h4>
        </div>

        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0"> 
           <thead>
               <tr>
                 <th>Asset</th>
                 <th>Serial Number</th>
                 <th>Model Name</th>
                 <th>Owner ID</th>
                 <th>Owner Name</th>
                 <th>Description</th>
               </tr>
           </thead>
      <tbody>
    
    <script>
    function approval(){
      window.location.href = "AddAssetApproval.php";
    }
    </script>

<?php    
            
$query = "SELECT * FROM waiting_approval";
$result = mysqli_query($conn, $query) or die (mysqli_error($conn));

while ($row = mysqli_fetch_assoc($result)) {
                     
    echo '<tr>';
    echo '<td>'. $row['Category'].'</td>';
    echo '<td>'. $row['SerialNumber'].'</td>';
    echo '<td>'. $row['ModelName'].'</td>';
    echo '<td>'. $row['OwnerID'].'</td>';
    echo '<td>'. $row['OwnerName'].'</td>';
    echo '<td>'. $row['Description'].'</td>';
    echo '<td><input type="button" value = "View" onclick="approval()"></td>';
    echo '</tr> ';
}
?> 

<div class="title">
  Add Asset Approval Form
</div>

<div class="form">
   <div class="inputfield">
      <label>Category</label>
      <input type="text" class="input" name="Category">
   </div>  
     
   <div class="inputfield">
      <label>Serial Number</label>
      <input type="text" class="input" name="SN">
   </div>  

  <div class="inputfield">
      <label>Model Name</label>
      <input type="text" class="input" name="Model Name">
   </div> 

   <div class="inputfield">
      <label>Owner ID</label>
      <input type="text" class="input" name="OID">
   </div> 

   <div class="inputfield">
      <label>Owner Name</label>
      <input type="text" class="input" name="OName">
   </div> 

  <div class="inputfield">
      <label>Description</label>
      <input type="text" class="input" name="Desc">
   </div> 

资产审批表是一个表格,里面有很多行数据和一个按钮,点击按钮后会链接到资产审批表。我想将资产批准列表中同一行的数据提取到我的资产批准表中。Asset Approval List 表中的数据取自mysql phpmyadmin。知道如何将相同的数据链接到资产批准表吗?

这是我的资产批准清单 这是我的资产批准清单

这是我的资产批准表

这是我的资产批准表

标签: phpmysql

解决方案


假设表中有一个唯一的 ID 列,您应该将其包含在对的调用中approval()

    echo '<td><input type="button" value = "View" onclick="approval(\'' . $row['SerialNumber'] . '\')"></td>';

然后更改approval()为在 URL 中包含 ID。

    function approval(serial){
      window.location.href = "AddAssetApproval.php?serial=" + serial;
    }

并且AddAssetApproval.php应该用于$_GET['serial']显示该序列号的相应批准表。

$stmt = $conn->prepare("SELECT * FROM waiting_approval WHERE SerialNumber = ?");
$stmt->bind_param("i", $_GET['serial']);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();

推荐阅读