通过 PHP 将 MySQL 数据传递给模态表单
我正在尝试使用模式作为用户在 MySQL 数据库中编辑数据的简单方法.似乎只有在我的 SELECT 语句中检索到的第一行可用于模态,我不明白为什么.换句话说,想象一个有几列的表,第一列是客户的姓名.我的目标是能够单击一个名称,显示一个带有表单的模式,然后传递该表单的结果以使用 PHP 更新数据库.但是,无论我单击哪个名称,都只会传递与第一条结果行相关的值.
I am attempting to use modal as a simple means for users to edit data in a MySQL db. It appears that only the first line retrieved in my SELECT statement is available to modal and I do not understand why. In other words, imagine a table with several columns, the first being a customer's name. My goal is to be able to click a name, show a modal with a form, and then pass the results of that form to update the db using PHP. No matter which name I click, though, only values related to the first resulting line are passed.
表项目"包括将出现在表中的所有行的信息.
Table 'Item' includes information for all of the lines that will be present in the table.
$personID
是通过 GET
传递的,是选择特定员工的客户的方法.
$personID
is passed via GET
and is the means of selecting customers of a specific employee.
模态 div
包含在 PHP while
子句中.
The modal div
is included within the PHP while
clause.
模式中包含的表单将信息传递给基本的 PHP 更新脚本.
The form contained in the modal passes the information to a basic PHP update script.
非常感谢,迈克
PHP 选择语句:
<?php
$query = "SELECT * FROM item WHERE personID = $personID";
$result = mysql_query($query);
while($info=mysql_fetch_array($result)){
$itemID = $info['itemID'];
?>
链接(众多链接之一;我已缩写此部分):
Link (one of many; I've abbreviated this section):
<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
出现在 modal 之后:
End of PHP while
comes after modal:
<?php } ?>
推荐答案
您正在打印多个具有相同 ID = customerModal 的 div
You are printing multiple divs with the same ID = customerModal
ID 必须是唯一的,因此链接只会打开循环中打印的第一个模式.
IDs have to be unique, so the link will only open the first modal printed in the loop.
变化:
<div id="customerModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
到:
<div id="customerModal<?php echo $info['itemID']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
和:
<a href="#customerModal" data-toggle="modal">
到:
<a href="#customerModal<?php echo $info['itemID']; ?>" data-toggle="modal">
相关文章