PHP 函数随机选择一个 Unix 日期小于两周的 mySQL 行
我需要一个 php 函数,它可以随机选择具有 unix 时间日期字段(如 2011-11-12 或 2011-12-24)的一行,该字段指示该行是在过去两周内从 mySQL 表创建的,并返回该行的 id。
我不知道该怎么做。老实说,我希望有人给我代码,但我不喜欢这样,因为大多数人不喜欢那样..他们的理由是有道理的,但如果有人愿意向我展示代码,那么请这样做,这样就可以至少有人指出我正确的方向?谢谢。
I need a php function that can randomly select one row that has a unix time date field (like 2011-11-12 or 2011-12-24) that indicates the row was created within the last two weeks from a mySQL table and return the id of that said row.
I don't know how do this. Honestly, I would like someone to hand me the code, but I don't like that because most people don't like that.. and their reasons make sense, but if someone would show me the code, then please do, thus can someone at the least point me in the right direction? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
date
和strtotime
获取日期:然后查询将如下所示:
ORDER BY RAND()
为您提供一个随机值排。strtotime
:https://www.php.net /manual/en/function.strtotime.php希望这有帮助。 :)
You can get the date by using
date
andstrtotime
:Then the query would look something like this:
ORDER BY RAND()
gives you a random row.strtotime
: https://www.php.net/manual/en/function.strtotime.phpHope this helps. :)