Page 1 of 1

delete records from database

Posted: Tue Aug 31, 2004 8:01 am
by picnic
dear friends,
hello
I'm in a problem and i need your help , I'm having a page in which there is a table and table contains multiple row in each row there are two colum one having a checkbox and another have a image and after this I have a image for delete option at last of the table, My problem is to delete all the image selected with the chechkbox I'm having the image ID in value part of the check box so plz help with the query
thanks with regards
Sachin

Posted: Tue Aug 31, 2004 8:21 am
by ol4pr0

Code: Select all

for ($i=0;$i<sizeof($CHECKBOX_VALUE);$i++);

$query = mysql_query("DELETE FROM !<TABLE>! WHERE Image_ID='".$CHECKBOX_VALUE[$i]."'");
Try something like that

Posted: Tue Aug 31, 2004 11:02 am
by feyd
I'm more a fan of doing it all in one hit:

Code: Select all

$sql = 'DELETE FROM table_name WHERE image_id IN (''' . implode(''',''',$_POST['checkbox_name']) . ''')';
mysql_query($sql) or die(mysql_error());
echo myslq_affected_rows() . ' records deleted, of ' . sizeof($_POST['checkbox']) . ' submitted.';