0

Say an array variable $i which contains the serial numbers. Example: $i=array("1", "15", "20", "23"); This variable is set by $_POST.

And the MySQLi query is such to delete the rows which serial numbers exists in the array. i.e. If serial number = 1 or 15 or 20 or 23, delete the row. How to write it as a single MySQLi prepared statement?

I tried with foreach, but the that logic will do query for n number of times, where n is the size of the array.

foreach($i as $sno)// Only the logic I use
{
    DELETE FROM `table` WHERE `sno`=?
    bind_param("i", $sno);
    execute();
}

How can this simplified so the query can be re-written as sno=[1] or [2] or [3] or ... [n]

Mr Cathode
  • 73
  • 14
  • possible duplicate of [mysqli bind\_param for array of strings](http://stackoverflow.com/questions/17226762/mysqli-bind-param-for-array-of-strings) – Tim Burch Mar 10 '14 at 14:31

1 Answers1

0

You can use the IN

Here is the logic,

DELETE FROM table WHERE sno IN ($i)
Sarvap Praharanayuthan
  • 4,212
  • 7
  • 47
  • 72