...

View Full Version : Updating Multiple Rows



marcus1060
07-26-2006, 03:18 AM
I need to update multipule rows a once, using PHP.

Here's what I mean.
I have a mysql query out put the data as a form like this:


Item 1
<input type="hidden" name="id" value="1">
<input type="text" name="order" value="">

Item 2
<input type="hidden" name="id" value="3">
<input type="text" name="order" value="">

Item 3
<input type="hidden" name="id" value="4">
<input type="text" name="order" value="">
<input type="submit">

Order need to be updated.

I could setup to do a loop with multiple queries.
But I don't want to do that.

Thanks a lot.

Kid Charming
07-26-2006, 03:22 AM
Unless you're updating all the affected rows to a single value, I think you're out of luck, since you're going to need a different WHERE conditional for each row.

marcus1060
07-26-2006, 03:23 AM
Unless you're updating all the affected rows to a single value, I think you're out of luck, since you're going to need a different WHERE conditional for each row.

I've heard of some way of doing it, actually with INSERT and ON DUPLICATE KEY UPDATE
But I don't know how to do it.

Kid Charming
07-26-2006, 03:34 AM
Yeah, that should work. You'd build an INSERT like:



INSERT INTO
table
(id,ordercol)
VALUES
(1,x)
,(2,y)
,(3,z)
ON DUPLICATE KEY
UPDATE ordercol=VALUES(ordercol)

marcus1060
07-26-2006, 03:59 AM
How would one do the PHP for this?

Kid Charming
07-26-2006, 04:02 AM
Just like the above, only use variables from your script to set your id and order values. If you're having problems with that side of it, please start a thread at the PHP forum.

marcus1060
07-26-2006, 04:32 AM
Edit: Never mind, I fixed that problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum