2014-09-19 85 views
0

我有一個表,我指定唯一值多個輸入,(例如):提供唯一值的每個實例提交按鈕

<td><?= $PMComments ?><input name="PMComments[]" type="text" value="<?= $PMComments ?>"></td> 

在我的表中的每一行是從引進我的SQL數據庫接收一個唯一的編號 - PMComments1,PMComments2等..出於某種原因,這是不符合我的更新按鈕的工作:

<td><input name="update[]" type="submit" id="update" value="Update"></td> 

這是爲什麼?

for ($n = 0, $t = count($_POST['PMComments']); $n < $t; $n++) { 
$UpdateValue    = $_POST['Update'][$n]; 
$PMCommentsValue   = $_POST['PMComments'][$n]; 
$LineID     = $_POST['LineID'][$n]; 
echo "UpdateValue of $UpdateValue " . "with comments $PMCommentsValue " . " with LineID " . $LineID . "<br>";  
} 

我得到的

UpdateValue of with comments TEST with LineID 11414 

回聲我不是能夠分配唯一值到一個按鈕或什麼?

+0

只有'

+1

每個提交必須有它自己的形式。 – 2014-09-19 14:22:34

+0

除了上面所述,如果這確實按照你的預期工作,'$ UpdateValue'的值總是字符串'Update',所以我沒有看到你想要實現的目標。 – Steve 2014-09-19 14:23:28

回答

0

如果你想使用一些jQuery。這裏就是我會做:

  1. 做一個通用的可點擊按鈕或fontawesome圖標和唯一的ID分配給該按鈕
  2. 該按鈕被點擊時,從相關的輸入
  3. 做一個AJAX獲取數據通話後發佈形式
  4. 認爲在UI上閃爍的東西,以紀念保存已完成像

它的工作是這樣(一般語法)

<td><input id='PMComments1' value='...'></td> 
<td><button class='submitit' id='submit1' data-id='PMComments1'><i class='fa fa-save'></i></button></td> 
... 
<td><input id='PMCommentsN' value='...'></td> 
<td><button class='submitit' id='submitN' data-id='PMCommentsN'><i class='fa fa-save'></i></button></td> 

<script> 
$('table').on('click', '.submitit', function() { 
    var id = $(this).attr('data-id'); 
    var val = $('#'+id).val(); 
    $.post("/my/ajax/handler.php", { id: id, val: val }, function() { 
     // do ui update tweak here like dim the save button until the next time 
    }); 
}); 
</script>