Ask a Question related to PHP Development, Design and Development.
-
scott #1
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
-
Add Multiple Values Simultaneously
When you add a new Pull Down Form field entry, you can only add 1 value at a time. I used to have an extention that allowed me to Copy a List and it... -
Publish Multiple Files Simultaneously..??
I have an application that takes a xml feed and transforms it via xsl to html and publishes it to a single folder on a daily basis. Does anyone... -
Updating multiple records in a linked table simultaneously
I am working on an e-commerce application and I need help with updating the product details for a single product with multiple formats. --DB... -
Updating Multiple records fields in a database atonce
Is it correct that there is no user interaction on these forms? I didn't see a submit button. Or does someone click on a submit button to get to... -
Dragging multiple movie clips simultaneously
Here's a problem that's probably been asked many times but in all of my searching I haven't found a good workaround for it. Maybe someone can think... -
scott #2
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
-
Geoff Berrow #3
Re: Updating Multiple Database Rows Simultaneously
I noticed that Message-ID: <bmbk8p$nnb$1$8302bc10@news.demon.co.uk> from
scott contained the following:
You can't. You'll have to write a loop and do it with multiple queries>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'll either have to write a loop to update all the values whether>
>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.
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
-
Geoff Berrow #4
Re: Updating Multiple Database Rows Simultaneously
I noticed that Message-ID: <bmbk8p$nnb$1$8302bc10@news.demon.co.uk> from
scott contained the following:
You can't. You'll have to write a loop and do it with multiple queries>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'll either have to write a loop to update all the values whether>
>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.
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
-
scott #5
Re: Updating Multiple Database Rows Simultaneously
"scott" <no@spamplease.com> wrote in message
news:bmbk8p$nnb$1$8302bc10@news.demon.co.uk...imageID.> 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 =sets>
> 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 multipleedit> 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 toand> all of the image_order values from one page.
>
> I've tried passing multiple image_order values by initialising an arrayway> 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 noFixed it:> 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.
>
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
-
scott #6
Re: Updating Multiple Database Rows Simultaneously
"scott" <no@spamplease.com> wrote in message
news:bmbk8p$nnb$1$8302bc10@news.demon.co.uk...imageID.> 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 =sets>
> 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 multipleedit> 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 toand> all of the image_order values from one page.
>
> I've tried passing multiple image_order values by initialising an arrayway> 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 noFixed it:> 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.
>
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



Reply With Quote

