以下代码有问题吗? 它没有更新所有文本输入,而是仅在单击保存后才更新第一个输入id = 1!
HTML标记:
<input type="text" id="1">
<input type="text" id="2">
<input type="text" id="3">
<input type="text" id="4">
<input type="text" id="5">
<input type="text" id="6">
JQUERY:
$('#save_affiliate').live('click',function() {
var $inputs = $('#affiliate_form');
$inputs.each(function(){
var counter = $(this).find("input[type=text]").length;
var af_value = $(this).find("input[type=text]").attr("value");
var af_id = $(this).find("input[type=text]").attr("id");
if(counter>0){
$.post("include/setting.php?affiliate",{id:af_id, text_value:af_value, count:counter}, function(data){
if(data.success) {
$('.err').html(data.message).fadeIn('slow');
} else {$('.err').html(data.message).fadeIn('slow');}
},"json");
}
});
return false;
});
PHP:
$counter = $_POST['count'];
$value = $_POST['text_value'];
$id = $_POST['id'];
$i = 0;
if ($counter != 0) :
while($i<$counter) :
$db->query("UPDATE affiliate SET d_percent='$value' WHERE id_affiliate='$id'");
endwhile;
$data["message"] = "Affiliate percentage value has been changed!";
$data['success'] = true;
endif;