i want to create this thing but i have no clue how to start

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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)....
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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}'";
Post Reply