php - 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。知道如何将相同的数据链接到资产批准表吗?
这是我的资产批准表
解决方案
假设表中有一个唯一的 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();
推荐阅读
- angular - 在哪里初始化响应式表单中的 FormGroup?
- reactjs - 当变量发生变化时,Apollo 客户端缓存不会在查询中更新
- plotly - 在 Dash 中并排放置两个 dash 表
- linux - 如何为 Linux 内核启动编写 startup.nsh?
- asynchttpclient - Ning async http客户端1.9:设置SSLParameters(SNI主机名)的正确方法
- docker - Google Cloud Run 上的 GitHub Actions Runner 容器,可以构建 docker 镜像
- arrays - 长度小于k的最大和子数组问题。上)
- bootstrap-4 - 如何使用引导样本计算多变量 cox 回归模型的 c 指数?
- python - Python、Django:分别用外键合并多个模型
- r - 如何在R中将值同时转换为列和列