gpt4 book ai didi

php - 仅更新已由用户修改或添加的字段

转载 作者:行者123 更新时间:2023-11-29 23:16:22 25 4
gpt4 key购买 nike

我在这里只添加了完整代码的一部分。我想要代码做的是,一旦提交,我只希望它更新表中已更改的字段,而不是每行中的每个项目(因为有些是 NULL 值,并且需要保持这种状态) .

最终 - 我将如何编码 PHP 流程页面。

表格格式为heli_cust:
cust_id
cust_fname
cust_lname
cust_kg
cust_email
cust_addr
cust_phone

http://jsfiddle.net/qz7k5caj/

HTML:

<table width="100%">
<div class="form_head">Passengers</div>
<table width="100%" cellpadding="4" cellspacing="0" id="px">
<thead>
<tr class="tab_head">
<td width="25px" style="text-align:center; color:#FFFFFF; font-size:11px;">#</td>
<td class="form_label" style="color:#ffffff; font-size:11px;">Cust#</td>
<td class="form_label" style="color:#FFFFFF; font-size:11px;">First Name</td>
<td class="form_label" style="color:#FFFFFF; font-size:11px;">Last Name</td>
<td class="form_label" style="color:#FFFFFF; font-size:11px;">Wgt</td>
<td class="form_label" style="color:#FFFFFF; font-size:11px;">Address</td>
<td class="form_label" style="color:#FFFFFF; font-size:11px;">Phone</td>
<td class="form_label" style="color:#FFFFFF; font-size:11px;">Email</td>
<td></td>
</tr>
</thead>
<tbody id="tbl1">
<?php if ($cust = mysql_fetch_assoc($getcust)) {
do { ?>
<tr id="pass">
<td style="vertical-align:middle; text-align:center"><input type="text" name="pass_num[]" readonly="readonly" value="1" class="pass" style="font:Verdana; font-size:11px; border:none; background-color:transparent; width:25px; text-align:center; vertical-align:middle;" tabindex="-1"></td>
<td><input type="text" readonly="readonly" class="form_a" value="<?php echo (int)$cust[cust_id] ?>" style="text-align:right; border:none; background-color:transparent; width:25px" /></td>
<td><input type="text" name="cust_fname[]" class="form_g" value="<?php echo $cust[cust_fname] ?>"/></td>
<td><input type="text" name="cust_lname[]" class="form_g" value="<?php echo $cust[cust_lname] ?>"/></td>
<td><input type="text" name="cust_kg[]" class="form_a" value="<?php echo $cust[cust_kg] ?>"/></td>
<td><input type="text" name="cust_addr[]" class="form_c" style="width:200px" value="<?php echo $cust[cust_addr] ?>"/></td>
<td><input type="text" name="cust_phone[]" class="form_g" value="<?php echo $cust[cust_phone] ?>"/></td>
<td><input type="text" name="cust_email[]" class="form_b" value="<?php echo $cust[cust_email] ?>"/></td>
<td style="vertical-align:middle"><a class="removePax"><img src="images/remove_pax.png" /></a></td>
</tr>
<?php } while ($cust = mysql_fetch_assoc($getcust));
} ?>
</tbody>
</table>
<table width="100%">
<tr><td style="text-align:right"><a id="add">&nbsp;<img src="images/add_pax.gif">&nbsp;</a></td></tr>
</table>
<br />
<table width="100%"><tr><td></td><td style="text-align:right"><input type="submit" value="Update" /></td></tr>
</table>

JQuery:

$("#tbl1 tr:even").css({"background-color":"#CCC", "opacity":"0.8"});
$("#tbl1 tr:odd").css({"background-color":"#FFF", "opacity":"0.8"});
$(".pass").each(function(){
$(this).val($(this).closest('tr').index()+1);
});

$("#tbl1 .removePax").on("click",function() {
if($("#tbl1 tr:last").index() >0) {
var tr = $(this).closest('tr');
tr.css("background-color","#FF3700");
tr.fadeOut(500, function(){
tr.remove();
$(".pass").each(function(){
$(this).val($(this).closest('tr').index()+1);
});
$("#tbl1 tr:even").css({"background-color":"#CCC", "opacity":"0.8"});
$("#tbl1 tr:odd").css({"background-color":"#FFF", "opacity":"0.8"});
});
return false;
} else {
if($(this).closest('tr').index() == 0) {
$("#tbl1 tr:eq(0)").find("input").each(function(){
if ($(this).hasClass('pass')) {
} else {
$(this).val('');
};
});
};
};
});

$("#add").click(function(){
$("#tbl1 tr:first").clone().find("input").each(function() {
$(this).val('')}).end().appendTo("#tbl1");
$("#tbl1 tr:even").css({"background-color":"#CCC", "opacity":"0.8"});
$("#tbl1 tr:odd").css({"background-color":"#FFF", "opacity":"0.8"});
$(".removePax").on("click",function() {
if($("#tbl1 tr:last").index() >0) {
var tr = $(this).closest('tr');
tr.css("background-color","#FF3700");
tr.fadeOut(500, function(){
tr.remove();
$(".pass").each(function(){
$(this).val($(this).closest('tr').index()+1);
});
$("#tbl1 tr:even").css({"background-color":"#CCC", "opacity":"0.8"});
$("#tbl1 tr:odd").css({"background-color":"#FFF", "opacity":"0.8"});
});
return false;
} else {
if($(this).closest('tr').index() == 0) {
$("#tbl1 tr:eq(0)").find("input").each(function(){
if ($(this).hasClass('pass')) {
} else {
$(this).val('');
}
}).end();
} else {
var tr = $(this).closest('tr');
tr.css("background-color","#FF3700");
tr.fadeOut(500, function(){
tr.remove();
$(".pass").each(function(){
$(this).val($(this).closest('tr').index()+1);
});
$("#tbl1 tr:even").css({"background-color":"#CCC", "opacity":"0.8"});
$("#tbl1 tr:odd").css({"background-color":"#FFF", "opacity":"0.8"});
});
return false;
}
};
});
$(".pass").each(function(){
$(this).val($(this).closest('tr').index()+1);
});
});
});

最佳答案

除了 @rjdown 给出的想法之外,如果您尝试使用 AJAX 来执行此操作,您可以添加一个 onchange 处理程序,并向已更改的项目添加一个“已更改”类。然后,只需将所有更改的数据发送回您的后端即可。这样您就可以确定要发送什么内容。

关于php - 仅更新已由用户修改或添加的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27761212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com