我想使用php创建一个简单的队列系统,当客户选择一个选项时,票证会生成。主要要求是:
下面是我得到的,我有两个表(ticket_id和票证)和一个触发器:
TICKET_ID
CREATE TABLE `ticket_id` (`ticket_id` int(5) NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=latin1;
票
CREATE TABLE `ticket` (`ticket_id` int(5) NOT NULL,
`ticket_name` varchar(5) NOT NULL DEFAULT '''0''',
`ticket_type` varchar(25) NOT NULL,
`ticket_time` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
触发
CREATE TRIGGER `tg_ticket_insert` BEFORE INSERT ON `ticket`
FOR EACH ROW BEGIN
INSERT INTO ticket_id VALUES (NULL);
SET NEW.ticket_name = CONCAT('A', LPAD(LAST_INSERT_ID(), 4, '0'));
END
newTicket
$query = "INSERT INTO ticket (ticket_type, ticket_time)
VALUES ('$in_tickettype', NOW())
";
重置
$query = "UPDATE ticket SET
ticket_name = DEFAULT
WHERE ticket_time = NOW() + INTERVAL 1 DAY
";
触发器在成功生成数字时效果很好,但我不知道如何重置数字。无论如何,我知道触发器并不是完成所有事情的唯一选择,如果有人有更好的解决方案,请帮助我。