PDA

View Full Version : Delete multiple rows in a table? (MySQL)



andersmoen
04-14-2007, 04:41 PM
Hey!

This is a really embarresing question to ask, since I know lots of PHP. But anyway, how can I do that?

Lets say I have a table called "c", and this is how it looks:


| id | field1 | field2 | field3 |
| 1 | 123 | 456 | 789 |
| 2 | 123 | 456 | 789 |
| 3 | 123 | 456 | 789 |
| 4 | 123 | 456 | 789 |
| 5 | 123 | 456 | 789 |
| 6 | 123 | 456 | 789 |


Now I want to delete the rows where the id's are 1, 4 and 6. I use the select method to select out these fields in a page, where you check the one's you want to delete and then you click submit and then they're deleted.
I think Wordpress has this feature...


If you don't understand, just tell me ;)
I always get so ... excited when I write stuff, though I'm a bad writer, hehe.

thetestingsite
04-14-2007, 04:44 PM
Make a query like this:



DELETE FROM `c` WHERE `id`='1';
DELETE FROM `c` WHERE `id`='4';
DELETE FROM `c` WHERE `id`='6'


Not tested, but should work. Hope this helps.

Twey
04-14-2007, 04:51 PM
No, mysql_query() can only execute one query at a time. Try:
DELETE FROM c WHERE id = 1 OR id = 4 OR id = 6

andersmoen
04-14-2007, 04:57 PM
Ok, I don't think you understood..

Wait some minutes, and I'll make some quick images about what I mean, okay?