显示当天的项目 [英] Show item of the day

查看:91
本文介绍了显示当天的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找创建一个从mySQL表中获取随机项目的函数,但让我将返回的内容保留为当天的项目".换句话说,在昨天所有其他项目都显示为当天项目之前,不应再次显示昨天为当天的项目"的项目.

I am looking to create a function that gets me a random item from a mySQL table, but let's me keep the returned as the "item of the day". In other words, the item that was "the item of the day" yesterday should not be shown again until all other items have been shown as item of the day.

关于如何以优雅的方式做到这一点的任何建议?

Any suggestions on how to do this in an elegant way?

谢谢

推荐答案

添加设置为false(0)的bool列"UsedAsItemOfTheDay".拾取项目时更新为true.从拣配过程中排除已经使用过的物品.

Add a bool column "UsedAsItemOfTheDay" set to false (0). Update to true when item is picked. Exclude already used items from the picking process.

SELECT * FROM `table` 
WHERE UsedAsItemOfTheDay = 0
ORDER BY RAND() LIMIT 1;

(注意:这不是在MySql中返回随机行的最快方法;在大型表上会很慢)

(Note: this is not the fastest way to return a random row in MySql; it will be slow on huge tables)

另请参阅:快速选择mysql中大表中的随机行的显示

这篇关于显示当天的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆