PDA

View Full Version : delete multiple entries using mysql?



sykes
May 30th, 2003, 06:51 PM
how do i delete multiple entries from a table using mysql commands?

i tried doing: delete from table_name where id = "11", "12", "13";
but obviously i was doing it wrong..

help mey peez :nerd:

Jubba
June 1st, 2003, 01:18 AM
oooooooh sorry... forgot all about this... i'm not really sure, I would try doing different querys...

$q1 = delete from table_name where id = "11"
$q2 = delete from table_name where id = "12"
$q3 = delete from table_name where id = "13"

$r1 = mysql_query($q1);
$r2 = mysql_query($q2);
$r3= mysql_query($q3);

something like that would work.

ahmed
June 1st, 2003, 01:40 AM
this is how i usually do it:
<?php
$deleteArray[0]=11;
$deleteArray[1]=12;
$deleteArray[2]=13;
mysql_connect('localhost', 'root');
mysql_select_db('mydb');
for ($i=0; $i<2; $i++) {
$id_num = $deleteArray[$i];
$query = "DELETE FROM table WHERE id_num='$id_num'";
$result = mysql_query($query);
echo "$id_num is deleted! <br>";
}
?>.. you might be fine though using jubba's way, i used the array way cause i had a lot of non-consecutive records that i needed to delete :)

Jubba
June 1st, 2003, 02:39 AM
yeah, I like his way better. :)