将比赛报名限制为每天一次 [英] Restrict competition entry to once per day

查看:85
本文介绍了将比赛报名限制为每天一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个成员站点编写一个PHP竞争脚本,该站点需要将每个成员每天的条目限制为一个.到目前为止,我有以下MySQL代码:

I'm writing a PHP competition script for a members site that needs to restrict entries to one per day per member. So far I have the following MySQL code:

SELECT ce_id 
  FROM competition_entries 
 WHERE ce_c_id = '$c_id' 
       AND ce_sub_id = '$user_id' 
       AND cte_date >= SYSDATE() - INTERVAL 1 DAY

  • ce_c_id是比赛ID,
  • ce_sub_id是成员ID,并且
  • cte_date是该条目的MYSQL日期时间戳.
  • 我现在很难从现在的位置进行测试&我需要找到一个解决方案,所以我希望有人可以告诉我这是否限制为每天一次或每24小时一次-如果是后者,请指出正确的方向.

    It's hard for me to test from where I am now & I need to find a solution, so I'm hoping someone can tell me whether this is restricting to once-per-day or once-per-24hrs - and point me in the right direction if it's the latter.

    TIA:)

    推荐答案

    创建一个由user_id,competition_id和日期类型列组成的主键.

    Create a primary key composed of the user_id, competition_id and a date type column.

    要检查用户是否已放置条目:

    To check if the user has already placed an entry:

    select count(*)
    from competition_entries
    where ce_c_id = '$c_id' 
        AND ce_sub_id = '$user_id' 
        AND cte_date = current_date()
    

    这篇关于将比赛报名限制为每天一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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