delete records from database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
picnic
Forum Newbie
Posts: 1
Joined: Tue Aug 31, 2004 7:56 am

delete records from database

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.';
Post Reply