0

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.

4
  • 2
    What is the question? (You haven't actually asked a question here) Commented Aug 5, 2010 at 5:31
  • I think that you should put" <input name="new_<?php echo $id; ?>_title" value="<?php echo $id_title; ?>" /> <?php } ?>" inside foreach loop Commented Aug 5, 2010 at 5:33
  • I'm having a really hard time understanding this question. Commented Aug 5, 2010 at 6:07
  • @Ankur Mukherjee its already there, don't know how to check variables Commented Aug 5, 2010 at 6:10

2 Answers 2

1

Something like this?

foreach ($ids as $id) {
    if (isSet($_POST["new_{$id}_title"]) && $_POST["new_{$id}_title"] != $old_titles[$id]) {
        // Do foo
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.