1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can you run an SQL Update with an array?

Discussion in 'XenForo Development Discussions' started by Jaxel, Nov 11, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    Okay... I have an array with the following keys and values:
    // [$key] => $value
    [SIZE=4][FONT=Times New Roman]Array ([/FONT][/SIZE]
    	[1] => 1
    	[2] => 10 
    	[3] => 1 
    	[4] => 20 
    	[5] => 1
    I would like to run an update on SQL, and set each key (category_id) to the value (category_order). Basically an arrayed version of the following:
    UPDATE EWRmedio_category
    SET category_order = $value
    WHERE category_id = $key
    Yes, I know I could run a foreach loop, and update each individually, but that would add 5 queries, and possibly more as I add more categories. I like to do things as efficiently as possible. Now if the keys and values were in their own arrays ($keys and $values, respectively), would it be possible to run this update code using the arrays?
  2. Indigo

    Indigo Active Member

Share This Page