[英]MYSQL EVENT or Something else ? trying to track “clicks for links”
I've been all over this site and google, trying to wrap my head about a solution. 我到过这个网站和Google,一直在想办法解决问题。
I've created a script that tracks Website traffic that we sell to our members, everything works great and show all the data we want. 我创建了一个脚本来跟踪我们出售给会员的网站流量,一切运行良好,并显示我们想要的所有数据。 It will even track the conversions, correctly.
它甚至可以正确跟踪转换。
My current problem is - turning off the traffic to the record (member) whose traffic has been all delivered. 我当前的问题是-关闭流量已全部交付的记录(成员)的流量。
After reading some articles, it would seem prefect to run an event, but I can't seem to figure this part out. 阅读一些文章后,运行事件似乎很完美,但是我似乎无法弄清楚这部分。
It also needs to run numerous times ... 它还需要运行多次...
Basically, I am not familiar with Events / Triggers and don't know which to do here 基本上,我不熟悉事件/触发器,也不知道该在这里做什么
Example; 例; Member has purchase 1000 clicks - all have been delivered, not change status to completed.
会员购买了1000次点击-全部已交付,但未更改状态为完成。
CREATE EVENT newEvent ON SCHEDULE EVERY 1 Minute DO UPDATE links SET status = 'completed' WHERE bought = '0';
Database Structure: 数据库结构:
ID - Incremental ID-增量
userid - members userid userid-成员userid
bought - shows the remaining clicks 购买-显示剩余的点击次数
count - shows clicks delivered 计数-显示获得的点击
pkgamount - stores the clicks bought pkgamount-存储购买的点击次数
Thanks. 谢谢。
Don't use the event scheduler, use a trigger that runs when updating the links
table: 不要使用事件调度程序,请使用在更新
links
表时运行的触发器:
DELIMITER $$
CREATE TRIGGER link_completed
BEFORE UPDATE ON links
FOR EACH ROW
BEGIN
IF NEW.bought = 0
THEN SET NEW.status = 'completed';
END IF;
END; $$
DELIMITER ;
Here's what you need to do to create and run an event. 这是创建和运行事件所需的操作。 There's some non-intuitive monkey business with delimiters, and with turning on the event scheduler.
有一些非直觉的猴子业务,带有定界符和打开事件调度程序。
DELIMITER $$
SET GLOBAL event_scheduler = ON$$ -- required for event to execute but not create
CREATE EVENT `Event1`
ON SCHEDULE EVERY 5 MINUTE
ON COMPLETION PRESERVE
COMMENT 'disable delivery when quota used up'
DO
BEGIN
UPDATE links SET status = 'completed' WHERE bought = '0';
END
$$
DELIMITER ;
Please note! 请注意! You may want to say
WHERE bought <= 0
so that you can correctly use an index on your bought
column and so you set the status correctly if a particular record falls below zero. 您可能想说
WHERE bought <= 0
以便可以在bought
列上正确使用索引,因此如果特定记录低于零,则可以正确设置状态。
If I were you I'd use this statement. 如果我是你,我会用这句话。
UPDATE links SET status = 'completed', bought = 0 WHERE bought <= 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.