Page 2 of 2

Posted: Wed Jan 18, 2006 6:22 am
by raghavan20
If I am not wrong, Jenk you are trying to mysql timestamp in the addition operation.

you can convert mysql to unix timestamp in sql statement...

Code: Select all

select UNIX_TIMESTAMP(mysql_timestamp)....

Posted: Wed Jan 18, 2006 6:30 am
by Jenk
Just maintain the lastDownload field as Integer and you won't need that. There really is no need to convert from int to date as you are comparing integers not dates.

Posted: Wed Jan 18, 2006 9:40 am
by Weirdan
Jenk wrote:

Code: Select all

function allowDownload ($userid)
{
    $sql = "SELECT `lastDownload` FROM `users` WHERE `userid` = '{$userid}'";
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);

    if ((intval($row['lastDownload']) + 86400) > time()) {
         //user has downloaded a file within the last 24hrs..
        return false;
    } else {
        return true;
    }
}
isn't it as simple as:

Code: Select all

function allowDownload ($userid)
{
    $sql = "SELECT `lastDownload`<= ( NOW() - INTERVAL 1 DAY ) FROM `users` WHERE `userid` = '{$userid}'";
    list($ret) = mysql_fetch_row(mysql_query($sql));
    return $ret;
}
?. Here I assume that the `lastDownload` field is of type TIMESTAMP

Posted: Wed Jan 18, 2006 10:33 am
by raghavan20
hope this works as well....

Code: Select all

select (unix_timestamp(current_timestamp()) - unix_timestamp(`lastdownload`)) < (60*60*24) FROM `users` WHERE `userid` = '{$userid}'";