[英]Passing MySQL data to Modal Form via PHP
我正在嘗試使用模式作為用戶在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 } ?>
您正在打印具有相同ID = customerModal的多個div
ID必須是唯一的,因此鏈接只會打開循環中打印的第一個模態。
更改:
<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">
運用
while($info=mysql_fetch_array($result)){
$itemID = $info['itemID'];
表示您繼續分配$ itemId。 最后,$ itemId僅保存最后分配的值。
您的模態由ID標識。 在jQuery中,只會引用具有該ID的第一個DOM元素。 要引用正確的模式,可以將數據庫ID附加到元素ID上,例如:
<div id="customerModal<?php echo $info['itemID']; ?>"
該鏈接也需要附加該鏈接:
<a href="#customerModal<?php echo $info['itemID']; ?>" data-toggle="modal">
有關使用ID選擇器的更多信息,請在此處查看jQuery文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.