我有一个名为
quote_of_the_day
它应该从列表中选择不同的行
quotes
表中的日期作为种子值。当我将代码作为查询进行测试时,一切似乎都运行良好,但当我在php代码中调用函数时(查询是
CALL quote_of_the_day()
)它只会从三个不同的引号中选择一个,尽管表中有23个引号。
创建systax for
引用今天的话
是:
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `quote_of_the_day`()
BEGIN
# save the number of rows into a variable
SET @num_rows = (SELECT COUNT(*) FROM `quotes`);
# calculate a random number no greater than the number of rows in the table
SET @rand_num = (SELECT FLOOR(RAND(CURDATE())*(@num_rows+1)));
# select random quote from the list of quotes (seed value is the current day)
SELECT quote FROM quotes WHERE id = @rand_num;
# increment the quoted column to keep track of which quotes are selected
UPDATE quotes SET quoted = quoted + 1 WHERE id = @rand_num AND last_used <> CURDATE();
UPDATE quotes SET last_used = CURDATE() WHERE id = @rand_num;
END;;
DELIMITER ;
我哪里做错了?