制作拍卖脚本在特定时间开始和停止拍卖。

发布于 2024-11-29 08:55:51 字数 145 浏览 0 评论 0原文

我正在构建一个简单的拍卖应用程序。我需要在特定时间开始和结束拍卖。显示公开拍卖的页面是否应该只运行查询来查找当前时间在开始时间之后和结束时间之前的所有拍卖?或者有一个将“活动”列设置为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上的星空 2024-12-06 08:55:51

不需要 cron 也不需要“活动”列。只需使用以下内容列出拍卖:

select *
from auctions
where
    start < now()
    and end > now()

当用户出价时,使用以下内容:

update auctions set
    bid = $bid,
    highest_bidder = $bidding_user_id
where
    id = $this_auction_id
    and start < now()
    and end > now()
    and bid < $bid

然后检查查询是否影响了一行。如果是 - 出价成功,当前用户是最高出价者。如果没有 - 出价太低或拍卖已结束。您可以稍后通过再次获取拍卖行并检查投标人 ID 来弄清楚这一点。

No cron and no "active" column is required. Just list auctions using something like:

select *
from auctions
where
    start < now()
    and end > now()

When user is placing a bid use the following:

update auctions set
    bid = $bid,
    highest_bidder = $bidding_user_id
where
    id = $this_auction_id
    and start < now()
    and end > now()
    and bid < $bid

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.

咋地 2024-12-06 08:55:51

只需在 mysql 表中设置一个“close_time”字段即可进行拍卖。添加行时,使用 time() + another 填充该字段,以设置 close_time 来表示未来的某个时间点。

然后设置一个运行简单查询的脚本:

'UPDATE auctions_table SET active = FALSE WHERE active = TRUE AND close_time <= UNIX_TIMESTAMP()'

将该查询保存到名为 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:

'UPDATE auctions_table SET active = FALSE WHERE active = TRUE AND close_time <= UNIX_TIMESTAMP()'

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文