通过PHP将MySQL数据传递给Modal Form [英] Passing MySQL data to Modal Form via PHP
问题描述
我试图使用模态作为用户编辑MySQL数据库中数据的简单方法。它似乎只有在我的SELECT语句中检索到的第一行可用于模态,我不明白为什么。换句话说,想象一下有几列的表,第一列是客户的名字。我的目标是能够单击一个名称,显示一个带有表单的模态,然后传递该表单的结果以使用PHP更新数据库。无论我点击哪个名称,只传递与第一个结果行相关的值。
表'项目'包含所有将存在的行的信息通过 GET
传递
$ personID
>是选择特定员工的客户的手段。
模式 div
包含在PHP while
子句。
模式中包含的表单将信息传递给基本的PHP更新脚本。
非常感谢,
Mike
PHP Select Stmt:
<?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 =#customerModaldata-toggle =modal><?php echo($ info ['itemCustomer']); ?>< / A>
< / div>
< / div>
Modal:
< div id =customerModalclass =modal hide fadetabindex = - 1role =dialogaria-labelledby =myModalLabelaria-hidden =true>
< div class =modal-header>
< 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 =btndata-dismiss =modalaria-hidden =true>关闭< / button>
< button class =btn btn-primary>保存更改< / button>
< / div>
< / form>
< / div>
在模态结束后,PHP 结束
<?php}?>
您正在打印具有相同ID = customerModal的多个div
ID必须是唯一的,因此链接只会打开循环中打印的第一个模式。
更改:
< div id =customerModalclass =modal hide fadetabindex = - 1role =对话框aria-labelledby =myModalLabelaria-hidden =true>
到:
< div id =customerModal<?php echo $ info ['itemID'];?> class =modal hide fadetabindex = - 1role =dialogaria-labelledby =myModalLabelaria-hidden =true>
和:
< a href =#customerModaldata-toggle =modal>
到:
< a href =#customerModal<?php echo $ info ['itemID'];?>数据肘节=模态>
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
is passed via GET
and is the means of selecting customers of a specific employee.
The modal div
is included within the PHP while
clause.
The form contained in the modal passes the information to a basic PHP update script.
Thanks very much, Mike
PHP Select Stmt:
<?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>
Modal:
<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>
End of PHP while
comes after modal:
<?php } ?>
You are printing multiple divs with the same ID = customerModal
IDs have to be unique, so the link will only open the first modal printed in the loop.
Change:
<div id="customerModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
to:
<div id="customerModal<?php echo $info['itemID']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
and:
<a href="#customerModal" data-toggle="modal">
to:
<a href="#customerModal<?php echo $info['itemID']; ?>" data-toggle="modal">
这篇关于通过PHP将MySQL数据传递给Modal Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!