仅更新用户已更改的字段 [英] Updating only fields which users have changed

查看:50
本文介绍了仅更新用户已更改的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个包含20或30个字段的html表单。表格

通过POST将字段提交到php页面,该页面使用$ _POST vars更新

数据库中的表格。哪个更有意义?


1)简单地更新表中所有字段的值,无论是否

并非任何特定字段实际发生了变化


2)运行第二个SELECT语句并将$ _POST vars与

比较返回的值,并仅更新那些已更改的值。

3)包括具有原始

值的每个字段的隐藏表单字段(因此对于每个< input type =" text" name =" field1" size =" 10"

value =" blah">还会有一个< input type =" hidden"

name =" field1_orig" value =" blah">),将$ _POST [''field1'']与

$ _POST [''field2'']进行比较,并仅更新那些已更改的内容。


两个用户同时使用这个特定网站同时更新同一个

表的可能性很小,但任何人都可以看到任何

particul以上三种方法中的任何一种问题?将$ _POST vars(选项3)的数量加倍会产生问题吗?


提前谢谢。

Let''s say I have an html form with 20 or 30 fields in it. The form
submits the fields via POST to a php page which updates a table in a
database with the $_POST vars. Which makes more sense?

1) simply UPDATING the values for all fields in the table, whether or
not any particular field has actually changed

2) running a second SELECT statement and comparing the $_POST vars to
the returned values, and only UPDATING those that have changed.

3) including a hidden form field for each field with the original
values (so for each <input type="text" name="field1" size="10"
value="blah"> there would also be a <input type="hidden"
name="field1_orig" value="blah">), comparing $_POST[''field1''] with
$_POST[''field2''] and only updating those that have changed.

There''s very little chance that two users will be updating the same
table at the same time with this particular site, but anyone see any
particular problems with any of the above three methods? Would
doubling the number of $_POST vars (option 3) create a problem?

Thanks in advance.

推荐答案

_POST vars。哪个更有意义?


1)简单地更新表中所有字段的值,无论是否

并非任何特定字段实际发生了变化


2)运行第二个SELECT语句并将
_POST vars. Which makes more sense?

1) simply UPDATING the values for all fields in the table, whether or
not any particular field has actually changed

2) running a second SELECT statement and comparing the


_POST变量与

比较返回值,并仅更新那些已经改变了。


3)包括每个字段的隐藏表单字段和原始的

值(因此对于每个< input type =" text" name =" field1" size =" 10"

value =" blah">还会有< input type =" hidden"

name =" field1_orig" value =" blah">),比较
_POST vars to
the returned values, and only UPDATING those that have changed.

3) including a hidden form field for each field with the original
values (so for each <input type="text" name="field1" size="10"
value="blah"> there would also be a <input type="hidden"
name="field1_orig" value="blah">), comparing


_POST [''field1'']与
_POST[''field1''] with


这篇关于仅更新用户已更改的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆