K
K
KRHD2019-02-14 19:24:49
SQL
KRHD, 2019-02-14 19:24:49

How to make a SQL query on an array?

there is an array

array(8) {
  [0]=>
  string(1) "1"
  [1]=>
  string(2) "10"
  [2]=>
  string(2) "11"
  [3]=>
  string(2) "12"
  [4]=>
  string(2) "13"
  [5]=>
  string(6) "122201"
  [6]=>
  string(6) "122202"
  [7]=>
  string(6) "122277"
}

Let's say it is passed in a variable $branches
This is a unique ID of each record in the `test` table in which you need to change let's say `name`
how to do this with a single SQL query

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-02-14
@NeiroNx

All dialects have an IN operator

$values = join("," , $branches)
$sql = "UPDATE `table` SET `name`='Test' WHERE `id` IN ($values)"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question