php - php、mysql无法检索每一行的列数据
问题描述
我试图根据从我的数据库中检索到的结果为每个模态表单提供一个唯一的 ID,以便将不同的数据传递到 php 表单处理器。我有 1 个表格,该表格放置在一个表格中,每行的唯一值是“ mapid
”
但是,每一行也有一个模式,我在其中放置了另一个表单,但我得到的唯一值是 sql 查询的第一行。请帮忙。
$sql = "SELECT mapid, location, DATE_FORMAT(date,'%d/%m/%y') AS date, status FROM maps ORDER BY status DESC, date DESC ";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo
'
<form action="map.php" method="post">
<tr>
<td> '. $row["mapid"].' </td>
<td> '. $row["location"].' </td>
<td> ' . ($row["status"]=='0' ? 'Last Done' : (($row["status"]=='1') ? 'Started' : 'Done')).' </td>
<td> '.$row["date"].' </td>
<td> ' .
(($row["status"]=='0') ?
'<input type="hidden" name="mapid" value="'. $row["mapid"].'"/>
<input type="hidden" name="start" value="start"/>
<button class="btn btn-primary" name="getmap" type="submit">Start</button>'
: (($row["status"]=='1') ?
'<input type="hidden" name="mapid" value="'. $row["mapid"].'"/>
<input type="hidden" name="resume" value="resume"/>
<button class="btn btn-danger" type="submit" name="getmap" value="'. $row["mapid"].'">Resume</button>'
: (($row["status"]=='2') ?
'<input type="hidden" name="mapid" value="'. $row["mapid"].'"/>
<input type="hidden" name="process" value="process"/>
<button class="btn btn-primary" type="submit" name="getmap">Process</button>'
: ''))) . '
</td>
</form>
<td>
<button class="btn btn-primary" data-toggle="modal" data-target="#assign['. $row["mapid"].']">Assign</button>
</td>
<div class="modal fade" id="assign['. $row["mapid"].']" tabindex="-1" role="dialog" aria-labelledby="assignLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="work/allocate.php" method="post">
<div class="modal-header">
<h5 class="modal-title" id="assignLabel">Assign Map</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="mapid">
<p> Assign <strong>Map '. $row["mapid"].' - '. $row["location"].' </strong> to:</p>
<input class="form-control" id="name" name="name" type="text" >
</div>
<div class="modal-footer">
<button class="btn btn-primary" name="assigned" id="assigned" type="submit">Assign</button>
</div>
</form>
</tr>
</div>
</div>
</div>
'
解决方案
只需要通过添加 ['. #assign 旁边的 $row["mapid"].']。
<td>
<button class="btn btn-primary" data-toggle="modal" data-target="#assign['. $row["mapid"].']" value"">Assign</button>
</td>
<div class="modal fade" id="assign['. $row["mapid"].']" tabindex="-1" role="dialog" aria-labelledby="assignLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
推荐阅读
- c# - 如何使用 c# 验证 AWS 访问密钥、密钥
- javascript - 如何使用同一个按钮来实现fadeOut() 和fadeIn()?
- jquery - SlideToggle 列表关闭时仅显示列表的一部分
- kotlin - 绑定不同视图模型的脏属性
- xml - 如何使用评估
- scala - Binding.scala:避免过多 dom-tree 更新的策略
- vba - EXCEL VBA ,仅在条件验证时才允许
- c# - UWP Pivot 控件,如何将焦点设置到 PivotItem 中的第一个控件
- ios - swift中嵌套字典API的结构
- java - 项目构建错误:不可解析的父 POM。org.springframework.boot:spring-boot-starter-parent 传输失败