开发者

updating 3 image fields

开发者 https://www.devze.com 2023-04-02 22:49 出处:网络
I\'m running into the following problem: I\'ve a client area where开发者_如何学编程 my client can edit 3 image fields.

I'm running into the following problem:

I've a client area where开发者_如何学编程 my client can edit 3 image fields. The problem is:

I just want to update the photo name in the database for the fields that are not empty. So, for example, if my client decide to change photo #2, I need a mysql update that will not override photo #1 and #3.

I could write a lot of "if" statements but I think there's a better way to do it.

any help?


Maybe you could use an array and a foreach statement. It could be something like:

$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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消