我整个星期都在努力,最后放弃了,决定直接问。我所拥有的是一个通过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,那么正确的方法是什么?
答案 0 :(得分:1)
[EDITED]
如果你试试这个呢?
表打开模式
<?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'.$row['id'].'" >Click here to edit</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>';
}
?>
模态
<?php while ($row = mysqli_fetch_array($jobs)) { ?>
<div class="modal fade" id="jobModal<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="jobModalLabel<?php echo $row['id']; ?>" 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<?php echo $row['id']; ?>"><strong>Job <?php echo $row['id']; ?></strong></h4>
</div>
<div class="modal-body">
...
</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>
<?php } ?>