J'ai un problème avec MySql, j'essaie d'écrire des déclencheurs pour la table mais mon knowlage abut c'est presque aucun. Qu'est-ce que je veux faire? Je veux mettre à jour certains inscrits dans le tableau A quand quelqu'un a mis quelque chose dans le tableau B. Mais pour le faire d'abord je dois compter ramer avec la valeur 1 et -1 dans le tableau B. Ceci est mon 3 TableComment faire pour déclencher des déclencheurs pour 3 table
CREATE TABLE IF NOT EXISTS `wp_comment_vote` (
`vote_id` int(11) NOT NULL AUTO_INCREMENT,
`comment_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`value` int(11) NOT NULL,
`meta_id` int(11) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`vote_id`)
)
CREATE TABLE IF NOT EXISTS `wp_comments` (
`comment_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT '0',,
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0'
`comment_author` tinytext NOT NULL,
`comment_author_email` varchar(100) NOT NULL DEFAULT '',
`comment_author_url` varchar(200) NOT NULL DEFAULT '',
`comment_author_IP` varchar(100) NOT NULL DEFAULT '',
`comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment_content` text NOT NULLN',
PRIMARY KEY (`comment_ID`)
)
CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) DEFAULT NULL,
`meta_value` longtext,
PRIMARY KEY (`meta_id`),
KEY `comment_id` (`comment_id`),
KEY `meta_key` (`meta_key`)
)
delimiter //
CREATE TRIGGER countvotecomment AFTER UPDATE ON wp_comment_vote
FOR EACH ROW BEGIN
UPDATE wp_commentmeta
IF wp_commentmeta.meta_key = 'vote_comment_in_minus' THAN
SET wp_commentmeta.meta_value = (SELECT COUNT(value) as glosy FROM wp_comment_vote WHERE comment_id=wp_commentmeta.comment_id AND value = '-1');
ELSEIF wp_commentmeta.meta_key = 'vote_comment_in_plus' THAN
SET wp_commentmeta.meta_value = (SELECT COUNT(value) as glosy FROM wp_comment_vote WHERE comment_id=wp_commentmeta.comment_id AND value = '1')
END;
delimiter ;