【发布时间】:2015-03-06 17:14:47
【问题描述】:
我整个星期都在努力解决这个问题,最后放弃了,决定直接问。我所拥有的是通过 mysql 查询填充的引导表中的打开作业列表。单击一行时,会出现一个模型,显示作业的详细信息。用户界面完美无缺,但现在我试图让正确的数据显示在模态中,我不知所措。
根据我的阅读,解决方案似乎是使用 AJAX,我对此的经验为零。如果我需要我的模态信息、sql 查询或两者都在单独的页面上,我似乎无法通过阅读其他解决方案和教程来弄清楚。这是我的初始代码:
jobs.php
<table class="table table-hover" data-link="row">
<thead>
<tr>
<th>Job #</th>
<th>Quote #</th>
<th>Date Started</th>
<th>Customer Name</th>
<th>Description</th>
<th>Amount</th>
<th>Date Completed</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($jobs)) {
// Print out the contents of the entry
echo '<tr>';
echo '<td><a href="" data-toggle="modal" data-target="#jobModal" ></a>' . $row['id'] . '</td>';
echo '<td>' . $row['quote'] . '</td>';
echo '<td>' . $row['started'] . '</td>';
echo '<td>' . $row['customer'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>$' . $row['amt'] . '</td>';
echo '<td>' . $row['status'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
模态 - 同样在 jobs.php 中(忽略占位符,当我开始工作时,它们将被替换为 php 变量)
<div class="modal fade" id="jobModal" tabindex="-1" role="dialog" aria-labelledby="jobModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="jobModalLabel"><strong>Job <?php echo $row['id']; ?></strong></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-2">
Quote #
</div>
<div class="col-lg-2">
PO # 1234567
</div>
<div class="col-lg-4">
Status: In Progress
</div>
<div class="col-lg-4 text-right">
Customer Name
</div>
</div>
<div class="row">
<div class="col-lg-4">
<br/>
Started: 03/01/2015
</div>
<div class="col-lg-4">
<br/>
Completed:
</div>
<div class="col-lg-4 text-right">
Primary Contact
</div>
</div>
<hr>
<div class="row">
<div class="col-lg-6 text-center">
<strong>PUMP SPECS</strong><br/><br/>
</div>
<div class="col-lg-6 text-center">
<strong>MOTOR SPECS</strong>
</div>
</div>
<div class="row">
<div class="col-lg-3">
Mfg: Taco
<br/><br/>
Size: 6x4
</div>
<div class="col-lg-3">
Mod: 54654856daf5
<br/><br/>
S/N: 54654856daf5
</div>
<div class="col-lg-2 border-left">
Mfg: Baldor
<br/><br/>
Frame: 215T
</div>
<div class="col-lg-2">
HP: 50
<br/><br/>
Encl: TEFC
</div>
<div class="col-lg-2">
RPM: 1800
<br/><br/>
Volts: 100
</div>
</div>
<div class="row"></div>
<div class="col-lg-2 col-lg-offset-6 border-left">
<br/>
Amps: 240/360
</div>
<div class="col-lg-4">
<br/>
S/N: 54654856daf5
</div>
<hr>
<div class="row">
<div class="col-lg-12">
<strong>Job Description:</strong>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Edit Job</button>
</div>
</div>
</div>
</div>
从这一点来看,无论如何我可以让 id 在模态端通过,这样我就可以像使用原始表一样使用 php 填写其余信息?如果我确实需要使用 ajax,那么这样做的正确方法是什么?
【问题讨论】:
-
所以当你点击 id 时,模态框应该只弹出那个 id 的数据?
-
如果你想在模态中保存更改,你应该添加一个
form,它在第一个input之前开始并在button之后结束,顺便说一下应该是type="submit"如果你想提交表格.. -
正确,模态应该只弹出该 id 的数据。无需对模态中的数据进行任何更改。
标签: php mysql ajax twitter-bootstrap bootstrap-modal