Jump to content

Update rows with ID in array (and more)


bayswater

Recommended Posts

Hi,

 

Ok, so I'm making a registration form system, where I can create new registration forms for the users to pick a date etc.

 

In my form I can add and remove text fields via Javascript - to add additional dates etc. so I don't know if I'll be submitting 3 fields or 15.

 

The could look like this:

<input type="hidden" name="session_id[]" value="<?php echo $session_id; ?>">
<input type="text" name="picked_date[]">
<input type="text" name="picked_room[]">

 

They are put in a big array:

De bliver smidt i et stort array:

$n=0;
    foreach ($session_id as $_session_id) {
        $bigar[$n][1] = $_session_id;
        $n++;
        }
        $n=0;
    foreach ($picked_date as $_picked_date) {
        $bigar[$n][2] = $_picked_date;
        $n++;
        }
        $n=0;
    foreach ($picked_room as $_picked_room) {
        $bigar[$n][3] = $_picked_room;
        $n++;
        }
        $n=0;

 

which is then updated in the database using:

foreach ($bigar as $part)
{
mysql_query("UPDATE...
}

 

Right - so far so good. The updating works fine with existing fields, but if I remove some of the fields (via JS) it obviously only updates the remaining in the array. The left out will be ignored. On the same note I would like to add fields as well, so - the bottom line - I want to:

 

- UPDATE rows, where the ID is in the array

- DELETE existing rows, WHERE the ID is NOT in the array

- CREATE new rows for the new fields in the array (not having an ID)

 

How can this be achieved? Hope someone can help...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.