While deleting multiple files, I often come across with statements where single statement is executed for every record. It is like displaying a check box to the user and then deleting using the following code:
PHP Code:if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
I have a list of ID's in a string which I must delete at once. Is this query legal in mysql?
PHP Code:$string = "12, 34, 45, 36, 14, 67, 89";
$query = "DELETE FROM mytable WHERE mytable.ID IN ($string)"
mysql_query($query) or die(mysql_error());




Reply With Quote