#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2

    "-" Unsupported oprand?


    I just wrote the following function to keep track of some daily values, and reset the table to 0 everyday.

    PHP Code:
    function dailyDate(){

        
    $date mysql_fetch_assoc(mysql_query("SELECT `date` FROM `daily` WHERE userID = 1"));

        
    $year date('Y');
        
    $day date('z');
        
        
    $currentDate $year $day;
        
        if(
    $currentDate $date['date'] > 0){
            
    mysql_query("UPDATE `daily` SET `date` = '$currentDate' WHERE `userID` = '1'") or die(mysql_error());
            
    mysql_query("UPDATE `daily` SET `views` = 0, `uploads` = 0, `points` = 0") or die(mysql_error());
        }
        

    For some reason the subtraction of $currentDate - $date produces an error of " Unsupported operand types". I tested doing the calculation outside the if statement, and even tried using settype integer for the date variables just in case something funky was going on there. But for some reason I'm still getting the same error.

    Not sure what's causing this, it's just subtraction.

    SOLVED:
    Made the derp mistake of not including the key of the associative array for date.
    Last edited by nbasso713; January 25th, 2013 at 10:36 PM.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    You should be doing this with a JOIN. Using the results of one query as the arguments to the next is (almost) never correct.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo