Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Location
    Canada
    Posts
    137
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Updating Multiple Rows

    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:
    Code:
    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.

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Location
    Canada
    Posts
    137
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kid Charming
    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.

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, that should work. You'd build an INSERT like:

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

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Location
    Canada
    Posts
    137
    Thanks
    2
    Thanked 0 Times in 0 Posts
    How would one do the PHP for this?

  • #6
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Aug 2005
    Location
    Canada
    Posts
    137
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Edit: Never mind, I fixed that problem.
    Last edited by marcus1060; 07-26-2006 at 04:36 AM.


  •  

    Posting Permissions

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