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 is the competition ID,
- ce_sub_id is the member ID, and
- cte_date is a MYSQL datetime stamp for the entry.
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 🙂
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: