Professional Web Applications Themes

Updating Multiple Database Rows Simultaneously - PHP Development

Hi, I'm having some trouble with something that should be relatively easy. I want to update multiple rows in one of my database tables simultaneously. In my table I have these values: imageID image_order I want to be able to modify the image_order column where imageID = imageID. imageID | image_order 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 I want to be able to pull these values into a form and allow the user to edit the image_order value. So my updated table might look something like this: imageID | image_order 1 ...

  1. #1

    Default Updating Multiple Database Rows Simultaneously

    Hi,

    I'm having some trouble with something that should be relatively easy. I
    want to update multiple rows in one of my database tables simultaneously.
    In my table I have these values:

    imageID
    image_order

    I want to be able to modify the image_order column where imageID = imageID.

    imageID | image_order
    1 | 1
    2 | 2
    3 | 3
    4 | 4
    5 | 5

    I want to be able to pull these values into a form and allow the user to
    edit the image_order value. So my updated table might look something like
    this:

    imageID | image_order
    1 | 2
    2 | 5
    3 | 1
    4 | 3
    5 | 4

    The problem lies in the form handling script. How can I pass multiple sets
    of imageID / image_order values to an sql update query?

    I can pass one set without problem. But I want the user to be able to edit
    all of the image_order values from one page.

    I've tried passing multiple image_order values by initialising an array and
    using a foreach() loop to extract the values but I can't think of a way to
    pass the corresponding imageID value. I can grab all the imageID values
    again in my form handler script using an ORDER clause to ensure they are
    pulled in the same order as the form script but again, I can think of no way
    to combine this with the img_order array sent from my form.

    How can I combine all of this data in one sql query that will update my
    table?

    Thanks in advance for any help.


    scott Guest

  2. #2

    Default Updating Multiple Database Rows Simultaneously

    Hi,

    I'm having some trouble with something that should be relatively easy. I
    want to update multiple rows in one of my database tables simultaneously.
    In my table I have these values:

    imageID
    image_order

    I want to be able to modify the image_order column where imageID = imageID.

    imageID | image_order
    1 | 1
    2 | 2
    3 | 3
    4 | 4
    5 | 5

    I want to be able to pull these values into a form and allow the user to
    edit the image_order value. So my updated table might look something like
    this:

    imageID | image_order
    1 | 2
    2 | 5
    3 | 1
    4 | 3
    5 | 4

    The problem lies in the form handling script. How can I pass multiple sets
    of imageID / image_order values to an sql update query?

    I can pass one set without problem. But I want the user to be able to edit
    all of the image_order values from one page.

    I've tried passing multiple image_order values by initialising an array and
    using a foreach() loop to extract the values but I can't think of a way to
    pass the corresponding imageID value. I can grab all the imageID values
    again in my form handler script using an ORDER clause to ensure they are
    pulled in the same order as the form script but again, I can think of no way
    to combine this with the img_order array sent from my form.

    How can I combine all of this data in one sql query that will update my
    table?

    Thanks in advance for any help.


    scott Guest

  3. #3

    Default Re: Updating Multiple Database Rows Simultaneously

    I noticed that Message-ID: <bmbk8p$nnb$1$8302bc10news.demon.co.uk> from
    scott contained the following:
    >The problem lies in the form handling script. How can I pass multiple sets
    >of imageID / image_order values to an sql update query?
    You can't. You'll have to write a loop and do it with multiple queries
    >
    >I can pass one set without problem. But I want the user to be able to edit
    >all of the image_order values from one page.
    You'll either have to write a loop to update all the values whether
    changed or not or put a sequentially numbered checkbox beside the ones
    which you want to change. Use a bit of javascript to check the box
    automatically onChange for a bit of added functionality (but make it
    clear the box must be checked for those without JS) Incidentally, this
    simple bit of javascript had me stumped for ages until I found out that
    the checkboxes would have to have a letter prefix

    I use the same method to delete entries except on the first pass the
    script simply writes hidden input for the records to be deleted. The
    user then has to press a confirm button to complete the operation.



    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  4. #4

    Default Re: Updating Multiple Database Rows Simultaneously

    I noticed that Message-ID: <bmbk8p$nnb$1$8302bc10news.demon.co.uk> from
    scott contained the following:
    >The problem lies in the form handling script. How can I pass multiple sets
    >of imageID / image_order values to an sql update query?
    You can't. You'll have to write a loop and do it with multiple queries
    >
    >I can pass one set without problem. But I want the user to be able to edit
    >all of the image_order values from one page.
    You'll either have to write a loop to update all the values whether
    changed or not or put a sequentially numbered checkbox beside the ones
    which you want to change. Use a bit of javascript to check the box
    automatically onChange for a bit of added functionality (but make it
    clear the box must be checked for those without JS) Incidentally, this
    simple bit of javascript had me stumped for ages until I found out that
    the checkboxes would have to have a letter prefix

    I use the same method to delete entries except on the first pass the
    script simply writes hidden input for the records to be deleted. The
    user then has to press a confirm button to complete the operation.



    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
    Geoff Berrow Guest

  5. #5

    Default Re: Updating Multiple Database Rows Simultaneously


    "scott" <nospamplease.com> wrote in message
    news:bmbk8p$nnb$1$8302bc10news.demon.co.uk...
    > Hi,
    >
    > I'm having some trouble with something that should be relatively easy. I
    > want to update multiple rows in one of my database tables simultaneously.
    > In my table I have these values:
    >
    > imageID
    > image_order
    >
    > I want to be able to modify the image_order column where imageID =
    imageID.
    >
    > imageID | image_order
    > 1 | 1
    > 2 | 2
    > 3 | 3
    > 4 | 4
    > 5 | 5
    >
    > I want to be able to pull these values into a form and allow the user to
    > edit the image_order value. So my updated table might look something like
    > this:
    >
    > imageID | image_order
    > 1 | 2
    > 2 | 5
    > 3 | 1
    > 4 | 3
    > 5 | 4
    >
    > The problem lies in the form handling script. How can I pass multiple
    sets
    > of imageID / image_order values to an sql update query?
    >
    > I can pass one set without problem. But I want the user to be able to
    edit
    > all of the image_order values from one page.
    >
    > I've tried passing multiple image_order values by initialising an array
    and
    > using a foreach() loop to extract the values but I can't think of a way to
    > pass the corresponding imageID value. I can grab all the imageID values
    > again in my form handler script using an ORDER clause to ensure they are
    > pulled in the same order as the form script but again, I can think of no
    way
    > to combine this with the img_order array sent from my form.
    >
    > How can I combine all of this data in one sql query that will update my
    > table?
    >
    > Thanks in advance for any help.
    >
    Fixed it:

    foreach ($imageID as $key => $value)
    {
    mysql("$db_name","UPDATE images SET img_order = '$value' WHERE imageID =
    '$key'");
    }

    Just needed to create an array to pass the imageID value as the $key and the
    img_order value as the $value.


    scott Guest

  6. #6

    Default Re: Updating Multiple Database Rows Simultaneously


    "scott" <nospamplease.com> wrote in message
    news:bmbk8p$nnb$1$8302bc10news.demon.co.uk...
    > Hi,
    >
    > I'm having some trouble with something that should be relatively easy. I
    > want to update multiple rows in one of my database tables simultaneously.
    > In my table I have these values:
    >
    > imageID
    > image_order
    >
    > I want to be able to modify the image_order column where imageID =
    imageID.
    >
    > imageID | image_order
    > 1 | 1
    > 2 | 2
    > 3 | 3
    > 4 | 4
    > 5 | 5
    >
    > I want to be able to pull these values into a form and allow the user to
    > edit the image_order value. So my updated table might look something like
    > this:
    >
    > imageID | image_order
    > 1 | 2
    > 2 | 5
    > 3 | 1
    > 4 | 3
    > 5 | 4
    >
    > The problem lies in the form handling script. How can I pass multiple
    sets
    > of imageID / image_order values to an sql update query?
    >
    > I can pass one set without problem. But I want the user to be able to
    edit
    > all of the image_order values from one page.
    >
    > I've tried passing multiple image_order values by initialising an array
    and
    > using a foreach() loop to extract the values but I can't think of a way to
    > pass the corresponding imageID value. I can grab all the imageID values
    > again in my form handler script using an ORDER clause to ensure they are
    > pulled in the same order as the form script but again, I can think of no
    way
    > to combine this with the img_order array sent from my form.
    >
    > How can I combine all of this data in one sql query that will update my
    > table?
    >
    > Thanks in advance for any help.
    >
    Fixed it:

    foreach ($imageID as $key => $value)
    {
    mysql("$db_name","UPDATE images SET img_order = '$value' WHERE imageID =
    '$key'");
    }

    Just needed to create an array to pass the imageID value as the $key and the
    img_order value as the $value.


    scott Guest

Similar Threads

  1. Add Multiple Values Simultaneously
    By WebSight Creations in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: November 21st, 11:17 PM
  2. Publish Multiple Files Simultaneously..??
    By joekerjoeker in forum Macromedia Contribute Connection Administrtion
    Replies: 0
    Last Post: May 9th, 06:42 AM
  3. Updating multiple records in a linked table simultaneously
    By Aaron Roberson in forum Coldfusion Database Access
    Replies: 2
    Last Post: January 25th, 06:41 PM
  4. Updating Multiple records fields in a database atonce
    By kris f in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: February 17th, 03:36 AM
  5. Edit multiple text layers simultaneously (PS6)
    By rbrdly in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 1
    Last Post: August 13th, 05:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139