Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's say you have the Ids 1,2,3,4. You could do something like this:</p> <pre><code>UPDATE photos SET sortorder = &lt;yourvalue&gt; WHERE id IN (1,2,3,4); </code></pre> <p>Now instead of explicitly writing <code>IN (1,2,3,4)</code> you can dynamically generate the values you want to be updated. That could be through PHP or via SQL:</p> <pre><code>UPDATE photos SET sortorder = &lt;yourvalue&gt; WHERE id IN (SELECT id from anotherTable WHERE otherattribute = someotherValue); </code></pre> <p>You should note that only text must be in <code>'</code> - numbers must be written without! For your example I assumed that <code>id</code> is a number and not a text - if it is indeed a text (or char/varchar), you need to write <code>... IN ('1','2','3','4')</code>. But I would advise you to use integer for your ids.</p> <p>Update: To get the specific values of your inputs, you can do the following:</p> <pre><code>&lt;input ... name='photo[]' value='1' /&gt; &lt;input ... name='sortorder[]' value='1' /&gt; </code></pre> <p>This way you will get two arrays when you send your form: <code>$_POST[photo]</code> and <code>$_POST[sortorder]</code>.</p> <p>Now iterate through both of them (sorry if the syntax isn't correct, didn't use PHP for a long time, but the idea should be clear):</p> <pre><code>for($i = 0; $i &lt; photo.length; $i++){ // your query here // something like: UPDATE photos SET sortorder = sortorder[i] WHERE id = photo[i]; // of course you have to sanitize your input! } </code></pre> <p>As I said: I'm not sure if that's exactly how you would write this in PHP, but the idea is to go through the arrays and take those values into your query.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload