See if this makes any sense
CREATE TABLE `song_ratings` (
`songid` INT NOT NULL ,
`voterid` INT NOT NULL ,
`time` TIMESTAMP DEFAULT '0' NOT NULL
);
INSERT INTO `song_ratings` (`songid`, `voterid`, `time`) VALUES (0, 0, NOW());
INSERT INTO `song_ratings` (`songid`, `voterid`, `time`) VALUES (0, 1, NOW()-100000);
SOLUTION 1 : Have php do your logic. Pull data from database. Convert everything to unix timestamps. Check to see if the last time voted was before or after today's unix timestamp. If before, let them vote again; if not before, don't let them voet yet.
/// ask sql to give you the time in Unix_Timestamp format
$sql = "SELECT UNIX_TIMESTAMP(time) FROM song_ratings where userid='blah' AND songid='blah';";
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
/// check to see if the vote was cast BEFORE today
if ( $row['time'] < strtotime('today') ) {
/// allow vote
/// update voted timestamp
}
SOLUTION 2 : lets MySql do the logic. Have php find the timestamp for the beginning of today. Pass it to sql to select truth if the vote was before today.
$today = strtotime('today');
$sql = "SELECT 1 FROM song_ratings WHERE songid=0 AND voterid=0 AND time<FROM_UNIXTIME($today);";
$result = mysql_query($sql);
/// if successful, this will return 1 row containing one column with a value of 1. If unsuccessful this returns 0 rows.
/// this may also throw an error if no rows are returned that you could check for instead, im unsure
if ( mysql_num_rows($result) == 1 ) {
/// allow vote
/// update voted timestamp
}
and in honor of good ol' perl you could even roll that last one into one liner...
if ( mysql_num_rows(mysql_query("SELECT 1 FROM song_ratings WHERE songid=0 AND voterid=0 AND time<FROM_UNIXTIME(".strtotime('today').");")) ) {
/// allow vote
/// update voted timestamp
}