Allora, ok...puoi fare una cosa di questo tipo:
1) Invece di avere 3 tabelle (2 principali ed 1 di relazione) ne crei solo 2 e nella seconda metti un riferimento (chiave esterna) alla prima.
2) Aggiungi, se puoi creare database di tipo INNODB, un evento ON DELETE alla seconda tabella.
codice:
CREATE TABLE `posts` (
`post_ID` int(10) unsigned NOT NULL auto_increment,
`category_ID` int(5) unsigned NOT NULL default '0',
`user_ID` int(10) unsigned NOT NULL default '0',
`post_title` text NOT NULL,
`post_preamble` text NOT NULL,
`post_content` longtext NOT NULL,
`post_date` datetime NOT NULL default '0000-00-00 00:00:00',
`post_highlighted` enum('n','y') NOT NULL default 'n',
PRIMARY KEY (`post_ID`),
KEY `category_ID` (`category_ID`),
KEY `user_ID` (`user_ID`)
) ENGINE=INNODB;
codice:
CREATE TABLE `tags` (
`post_ID` int(10) unsigned NOT NULL,
`tag_ID` int(10) NOT NULL auto_increment,
`tag_name` varchar(255) NOT NULL default '',
PRIMARY KEY (`post_ID`, `tag_ID`),
FOREIGN KEY (`post_ID`) REFERENCES `posts`(`post_ID`) ON DELETE CASCADE,
UNIQUE KEY `tag_name` (`tag_name`)
) ENGINE=INNODB;
In questo modo quando elimini un "post" automaticamente verranno elimitati tutti i "tag" relativi a quel post.
Potresti anche usare i trigger, che sono degli eventi che si scatenano in base a qualcosa che programmi tu. Nel tuo caso puoi fare che ogni volta che si cerca di cancellare qualcosa da "posts" automaticamente si avvia una procedura (trigger) MySQL che cancella i relativi "tags".
In questo modo da PHP dovrai semplicemente cancellare un post senza preoccuparti dei tags.
Spero di esserti stato di aiuto...