制作拍卖脚本在特定时间开始和停止拍卖。
我正在构建一个简单的拍卖应用程序。我需要在特定时间开始和结束拍卖。显示公开拍卖的页面是否应该只运行查询来查找当前时间在开始时间之后和结束时间之前的所有拍卖?或者有一个将“活动”列设置为 True 的脚本会更好吗?如果是这种情况,我是否必须进行某种类型的 cronjob 设置?
I am building a simple auction application. I need auctions to start and end at certain times. Should the page that displays the open auctions just run a query to find all auctions where current time is after the start time and before the end time? Or would it bet better to have a script that sets a "active" column to True? If this is the case would I have to have some type of cronjob setup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要 cron 也不需要“活动”列。只需使用以下内容列出拍卖:
当用户出价时,使用以下内容:
然后检查查询是否影响了一行。如果是 - 出价成功,当前用户是最高出价者。如果没有 - 出价太低或拍卖已结束。您可以稍后通过再次获取拍卖行并检查投标人 ID 来弄清楚这一点。
No cron and no "active" column is required. Just list auctions using something like:
When user is placing a bid use the following:
Then check if query has affected a row. If yes - bid is successful, current user is highest bidder. If no - bid is too low or auction has finished. You can figure out that later by fetching auction row again and checking bidder id.
只需在 mysql 表中设置一个“close_time”字段即可进行拍卖。添加行时,使用
time() + another
填充该字段,以设置 close_time 来表示未来的某个时间点。然后设置一个运行简单查询的脚本:
将该查询保存到名为
close_active_auctions.php
的 php 页面,并在 cron 上将其设置为每 10 秒左右一次(或者您需要的频率) )。Just set a "close_time" field in the mysql table with your auction. When you add the row, populate that field with a
time() + whatever
to set the close_time to represent some point in the future.Then setup a script which runs a simple query:
Save that query to a php page called something like
close_active_auctions.php
and set that up on a cron for once every 10 seconds or so (or however often you need).