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]