SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Equal and greater than?

    PHP Code:
    $getoldposts mysql_query("SELECT * FROM posts WHERE username='$username'");

    while(
    $oldposts=mysql_fetch_array($getoldposts))
    {
     
    $olddate $oldposts['date'];
     
    $datenow date("Y-m-d H:i:s") - 60;

    }

    if (
    $olddate=>"$datenow") {
            
    error("Flood control is on in this forum.\\n".
                  
    "Please go back and wait 60 seconds.");
        } 
    I'm trying to get flood control, adn that's my code... I get an error on the if statement when it has the => but when I change it to == it works..

    Any ideas?

    Thanks,
    ~someonewhois

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be >=, not =>. Think about how you say it. "Greater than or equal to." Not "equal to or greater than."

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANK YOU SO MUCH!

    I'll try that now...

  4. #4
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you think there is anything else wrong with teh code?

    It always pops up that error message, no matter when my last post was... any ideas? :|


    Should I define something rather then saying 60?

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That wasn't working, but I have the right logic now!

    PHP Code:

    $getoldposts 
    mysql_query("SELECT * FROM posts WHERE username='$username' ORDER by ID desc LIMIT 0,1");

    while(
    $oldposts=mysql_fetch_array($getoldposts))
    {
     
    $olddate $oldposts['date'];
     
    $datenow date("Y-m-d H:i:s");

    }

    $difference $datenow $olddate;

    echo 
    "$olddate | ";
    echo 
    "$datenow | ";
    echo 
    "$difference"
    the echos are just becuase I'm testing...

    That displays this:

    2002-04-06 09:15:29 | 2002-04-06 09:24:19 | 0

    Why is this?

    Can you get the difference between 2 dates if they have the same format?

    Thanks,
    ~someonewhois

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would I need to use a timestamp?

    How do I use a timestamp?

  7. #7
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $getoldposts mysql_query("SELECT *, DATE_FORMAT(date, 'Y-m-d H:i:s') AS n_date FROM posts WHERE username='$username' ORDER by ID desc LIMIT 0,1");

    while(
    $oldposts=mysql_fetch_array($getoldposts))
    {
     
    $olddate $oldposts['n_date'];
     
    $datenow date("Y-m-d H:i:s");

    }

    $difference $datenow $olddate;

    echo 
    "$olddate | ";
    echo 
    "$datenow | ";
    echo 
    "$difference"

    you'll have to check Y-m-d H:i:s for the equivelent of mysql.
    Last edited by redgoals; Apr 6, 2002 at 13:04.
    http://redgoals.com ... my site ... nuff said

  8. #8
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's sql's datetime, so that is teh same...

    The formats are the same, but it doesn't work properly...


    That date format is actually copied from the part where I insert it during post...

  9. #9
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've never tried comparing with date/time ive always used timestamp.
    http://redgoals.com ... my site ... nuff said

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How woul dI use timestamp?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •