PHP Newbie, modifying a simple function

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

Post Reply
kennyw10000
Forum Newbie
Posts: 1
Joined: Thu Jan 17, 2008 12:26 pm

PHP Newbie, modifying a simple function

Post 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.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: PHP Newbie, modifying a simple function

Post 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.
Post Reply