更新3个图像字段

时间:2011-09-05 22:31:16

标签: php mysql image field

我遇到了以下问题:

我有一个客户区,我的客户可以编辑3个图像字段。 问题是:

我只想更新数据库中非空字段的照片名称。 因此,例如,如果我的客户决定更改照片#2,我需要一个不会覆盖照片#1和#3的mysql更新。

我可以写很多“if”语句,但我认为有更好的方法。

任何帮助?

1 个答案:

答案 0 :(得分:1)

也许您可以使用数组和foreach语句。它可能是这样的:

$field = array();

$field['1'] = $_POST['field1'];
$field['2'] = $_POST['field2'];
$field['3'] = $_POST['field2'];

foreach($field as $value){
    if($value != NULL){
        // Update the MYSQL database for the field using $value to figure
        // out which field the script is on
    }
}