Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Make a Time Limit

    Hello

    what i try to do is , limit the User from Editing his Post in one Minute after that he can Not edit his post. after 60s

    this wht i did and did not work .

    1- get the time of the Post from the Mysql

    PHP Code:
     $sql=mysql_query("SELECT * FROM test WHERE id='$id'")
      or die(
    "can't get the sql");
      
    $row mysql_fetch_array($sql); 
    2- Now See if the time in the Mysql Plus 60s is Passed ..

    PHP Code:
    $time_now=time(); // time now notice that the time in thd database is stored in the same way
    //after extracting data from the database
    $database_time=$row['datetime']+60//the time in the database + 60 seconds
    if($time_now>$database_time){
    echo 
    "You are not allowed to edit ur post now";
    }else{
    echo 
    "edit";

    that did not work .. So whts wrong ..

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Can you confirm the `datetime` field value?

    This is wrong:
    PHP Code:
    if($time_now>$database_time){ 
    That conditional statement says "if the time now is greater than the time stored in the db +60 seconds, disallow edit". This is the opposite of what you want. You do want the time now to be greater than the stored time +60. That means it's past the 60 second limit, and you can allow the edit.

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Hello again..

    this Statment put the time in the table.

    PHP Code:
        $datetime=date("d/m/y h:i:s"); //create date time 
    and after bring the time from the mysql , we Compare to the curent time . so the lets get the curent time .

    PHP Code:
    $time_now=time(); 
    now lets get the time when the the Comment was Posted.

    PHP Code:
    $database_time=$row['datetime']; 
    Now i need the Correct Code to Make the time Limit .. . But seems Confusing to me

  • #4
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    PHP Code:
        $datetime=date("d/m/y h:i:s"); //create date time 
    That's not the same as the output from time(). The time() function outputs a UNIX TIMESTAMP (UNIX EPOCH) value, e.g. '1264293695'. The date() function creates a formatted date string based on the specifiers you pass, e.g. '01/23/10 16:43:00'. The first is an integer value, the second is a string.

    The best way to do this IMHO is to use the MySQL DATETIME (or TIMESTAMP) data type in your `datetime` field. Then your SQL statement can perform the calculation. Please review the DATE & TIME data types and functions in the MySQL reference manual.

    At the very least make sure you're using compatible date / time values regardless of where the calculation is made.

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    see this worked for me .

    PHP Code:
        //check time
        
            
    $datetime=time() ;   //now time

         
    $date $row["datetime"] +60;  // mysql time

         
    if ( $datetime $date)   {

         echo 
    "no edit";
         }
         else {
         echo 
    "yes edit ";
         }
     
    //check time 
    But i echo the Time so user can see the time of the post , the time Now Prints as .
    1367797998

    So now to conver the time back to normal format i did

    PHP Code:
    $date formatTimestamp($rows['datetime'],"m"); 
    PHP Code:
    echo "$date"
    It work Now .. but did i do all that correct
    Last edited by ajloun; 01-24-2010 at 02:18 AM.


  •  

    Posting Permissions

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