tags:

views:

36

answers:

2

We have 2 variables, $id and $title.

And a form field for a new $title variable:

foreach ($ids as $id) {
    $id_title = $title;
?>
    <input name="new_<?php echo $id; ?>_title" value="<?php echo $id_title; ?>" />
<?php } ?>

How to check, is $id_title has been changed in the form, and do something if it is.

Like:

if ($id_title != $new_id_title) {
    make db query
}

There can be more than one input field on the page, different for each $id, we should check all of them.

Thanks.

+1  A: 

Something like this?

foreach ($ids as $id) {
    if (isSet($_POST["new_{$id}_title"]) && $_POST["new_{$id}_title"] != $old_titles[$id]) {
        // Do foo
    }
}
Borealid
+1  A: 

You mean

foreach ($ids as $id) {
    $id_title = $title;
    if ($id_title != $_POST['new_'.$id.'_title']) {
       make db query
    }
}

?

Is the problem that you don't know how to get the new_$id_title field?

Btw. I don't see a point to assign $title to $id_title. It is the same for all anyway.

Felix Kling