Page 1 of 1

PHP Newbie, modifying a simple function

Posted: Thu Jan 17, 2008 12:31 pm
by kennyw10000
Hello everyone,

I am still learning PHP, and have been tasked with modifying a script. There is a function in the script that checks to see how many times a user has sent an email within a certain period of time. I need to add a little piece that allows one user (the admin) to send an unlimited amount of emails. I thought the best way to do this was to put in a piece that basically says: with this user, skip the email count. Below is the function:

Code: Select all

 
////////////////////////////////////////////////
public function checkUserEmailCount($uid){
 
        $q = "SELECT DATE_FORMAT('last_email', '%Y %c') AS last_email, email_count FROM user WHERE id=".$this->quote_smart($uid);
 
        $result = $this->query($q);
        $row = mysql_fetch_assoc($result);
 
        $today = (int) date('Ym');
        $last_email = (int) $row['last_email'];
 
        if ($last_email < $today){
            $q = "UPDATE user SET email_count=0 where id=".$this->quote_smart($uid);
            $result = $this->query($q);
            return true;
        } else if($row['email_count'] < MAX_FLYERS){
            return true;
        } else {
            return false;
        }
    }
///////////////////////////////////////////////////
 
I'm not sure how to do this, but I thought about adding something like this:

Code: Select all

 
        If user ID = 285 then skip email count
 
        } else if($last_email < $today){
            $q = "UPDATE user SET email_count=0 where id=".$this->quote_smart($uid);
            $result = $this->query($q);
            return true;
        } else if($row['email_count'] < MAX_FLYERS){
            return true;
        } else {
            return false;
        }
 
Any help on this would be appreciated.

Thanks.

Re: PHP Newbie, modifying a simple function

Posted: Thu Jan 17, 2008 1:47 pm
by Jade
That would work fine. One thing though, put that check above the SQL query, that way you'll save yourself load on your database. No reason to even check the database if it's the admin user and you know they can send unlimited emails.