Deleting multiple records from a table by id

How to make normal code out of this nonsense?

The meaning is this, on one page the user checks the messages that he needs to delete.

 $mass = ( $_POST['sold'] );
   mysql_query("DELETE FROM massage WHERE id = $mass[0]");
   mysql_query("DELETE FROM massage WHERE id = $mass[1]");
   mysql_query("DELETE FROM massage WHERE id = $mass[2]");
   mysql_query("DELETE FROM massage WHERE id = $mass[3]");
   mysql_query("DELETE FROM massage WHERE id = $mass[4]");
   mysql_query("DELETE FROM massage WHERE id = $mass[5]");
   mysql_query("DELETE FROM massage WHERE id = $mass[6]");

and so on…


Answer 1, authority 100%

You can do this

mysql_query('DELETE FROM message WHERE id IN ( ' . join( ',', $mass ) . ' );');

Better like this

mysql_query(
  'DELETE FROM message'.
  'WHERE id IN ( '.join( ',', $mass ).' ) AND user_id = '.$user_id.';'
);

It’s even better to cast to INT for $mass

elements


Answer 2, authority 67%

DELETE FROM massage WHERE id IN ($mass[0], $mass[1], $mass[2], $mass[3], $mass[4] ...);