Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can generate a query like this:</p> <pre><code>UPDATE tasks_tbl SET task=1 WHERE (user_id=16 AND date='2010-05-05') OR (user_id=17 AND date='2010-02-22') </code></pre> <p>There are hacks to avoid using <code>(... and ...) or (... and ...)</code> constructs (concatenate fields and params: <code>"concat(user_id, date) = '". $user_id. $date. "'"</code>, but they work a bit slower.</p> <p>The PHP code:</p> <pre><code>for ($i = 0; !empty($_POST['update'. $i]; $i++) if (intval($_POST['task'.$i]) == 1) $cond[] = '(user_id='. intval($_POST['user_id'. $i]). ' and date=\''. mysql_real_escape_string($_POST['date'.$i]). '\')'; $query = 'UPDATE tasks_tbl SET task=1 WHERE '. implode(' OR ', $cond). ')'; </code></pre> <p><strong>Edit:</strong> I don't quite understand why you need to do that in a single query. How many values <code>task</code> can have? 1, 2, 3, or many more? With 3 values, you can use nested <code>IF(...)</code> functions:</p> <pre><code>UPDATE tasks_tbl SET task=if('. &lt;imploded tasks with value 1&gt;. ', 1, if('. &lt;tasks with value 2&gt;. ', 2, if('. &lt;tasks with 3&gt;. ', 3, task))) /* leave as is otherwise */ </code></pre> <p>Or you may put a simple loop on the code I've given:</p> <pre><code>for ($j = 1; $j &lt;= 3; $j++) for ($i = 0; !empty($_POST['update'. $i]; $i++) if (intval($_POST['task'.$i]) == 1) $cond[] = '(user_id='. intval($_POST['user_id'. $i]). ' and date=\''. mysql_real_escape_string($_POST['date'.$i]). '\')'; mysql_query('UPDATE tasks_tbl SET task=1 WHERE '. implode(' OR ', $cond). ')'); </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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