【发布时间】:2012-12-19 05:15:47
【问题描述】:
我正在尝试使用模式作为用户在 MySQL 数据库中编辑数据的简单方法。似乎只有在我的 SELECT 语句中检索到的第一行可用于模态,我不明白为什么。换句话说,想象一个有几列的表,第一列是客户的姓名。我的目标是能够单击一个名称,显示一个带有表单的模式,然后传递该表单的结果以使用 PHP 更新数据库。但是,无论我单击哪个名称,都只会传递与第一条结果行相关的值。
表“项目”包括将出现在表中的所有行的信息。
$personID 是通过GET 传递的,是选择特定员工的客户的手段。
模态 div 包含在 PHP while 子句中。
模式中包含的表单将信息传递给基本的 PHP 更新脚本。
非常感谢, 迈克
PHP 选择语句:
<?php
$query = "SELECT * FROM item WHERE personID = $personID";
$result = mysql_query($query);
while($info=mysql_fetch_array($result)){
$itemID = $info['itemID'];
?>
链接(众多链接之一;我已缩写此部分):
<div class='row-fluid'>
<div class='span3'>
<a href="#customerModal" data-toggle="modal"><?php echo($info['itemCustomer']); ?></a>
</div>
</div>
模态:
<div id="customerModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><?php echo($info['itemID']); ?></h3>
</div>
<div class="modal-body">
<form action='pipelineEdit.php' method='post'>
<input placeholder='Customer Name' style='width:50%' type='text' name='editValue' id='editValue'>
<input type='hidden' value='itemCustomer' name='editField' id='editField'>
<input type='hidden' value='<?php echo($info['itemID']); ?>' name='itemID' id='itemID'>
<input type='hidden' value='<?php echo($personID); ?>' name='personID' id='personID'>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
PHP 结束 while 出现在模态之后:
<?php } ?>
【问题讨论】:
-
如何在 php 脚本中分配 $personID?另外,我是否认为您正在打印多个 customerModal div? ID 应该是唯一的,因此链接只会打开循环中打印的第一个模式。您可能应该将$personID 通过 GET(上一页的链接)传递$personID = $_GET[personID];
标签: php jquery html twitter-bootstrap modal-dialog