|
-
Jul 7th, 2009, 08:32 AM
#1
Thread Starter
Lively Member
deleting multiple files
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());
Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic
-
Jul 7th, 2009, 03:40 PM
#2
Re: deleting multiple files
I don't see why it wouldn't work.
-
Jul 7th, 2009, 09:15 PM
#3
Re: deleting multiple files
No problems and it is much more efficient than executing a separate query for every item.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|