SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 43
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    24 hours limitation

    Hi guyz
    how are you all
    i am working with some function where i am providing users 24 hours after login. in 24 hours they can post once.
    For example
    they have
    24 hours
    and if they post in first 10 hours
    then they will not be able to post in next 14 hours .
    and after completing their remaining 14 hours then again they get 24 hours time start for posting.

    Any idea how to limitate and apply this restriction ?

    Mean users can do any action only once in 24 hours

  2. #2
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,530
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by realcoder View Post
    Hi guyz
    how are you all
    i am working with some function where i am providing users 24 hours after login. in 24 hours they can post once.
    For example
    they have
    24 hours
    and if they post in first 10 hours
    then they will not be able to post in next 14 hours .
    and after completing their remaining 14 hours then again they get 24 hours time start for posting.

    Any idea how to limitate and apply this restriction ?

    Mean users can do any action only once in 24 hours
    Whenever someone is marked as a "mean" user, log the time of this designation, store it in MySQL - maybe in the User record - and then have your PHP check the current time against this "Mean Person Time-out Timestamp".


    Debbie

  3. #3
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you elaborate your idea with query
    However I am already saving user time with post whenever he signup and then he post his time save but I donít know how to calculate his time after 1st post .
    For example if he has post in first 10 hours then 14 hours remaining in which I donít want to allow him to post but once 24 hours complete again hi get 24 hours for next post.

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Location
    Chennai
    Posts
    20
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Make a note of the user id and the posting date and time
    Check for the previous posting date and time

    Previous posting time + 24 < current posting time → user suppose not to be allowed for posting and vice versa

  5. #5
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Hi realcoder,

    If I understand your requirements correctly, the following query should get you the information you need (note that I've made some assumptions about your DB structure, so you'll probably have to change things slightly to match your table/column names):

    Code MySQL:
    SELECT count(post.id) as total
    FROM post, user 
    WHERE post.user_id = user.id 
    AND post.created > CONCAT( DATE( NOW() ), ' ', TIME(user.created) ) 
    AND user.id = $id;

    This basically takes the the time of day that the user's account was created, and combines it with the current date to get a DATETIME. It returns a count of how many posts have been made since that DATETIME.

    If the result is 0, then you can allow the user to post.

  6. #6
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well can i get the time of last two post
    i mean i know we can easily fetch data of last one single column
    but i want to fetch data of last two colums and want to savethem separtely for calculating time difference between last two post so i can know that users has made his post in how many hours from his last post
    because i want to restrict him if he has 24 hours for posting and he has post in first 10 hours he can't post in i next 14 hours till completing his 24 hours and then again i can allo w him for next post

  7. #7
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by realcoder View Post
    well can i get the time of last two post
    i mean i know we can easily fetch data of last one single column
    but i want to fetch data of last two colums and want to savethem separtely for calculating time difference between last two post so i can know that users has made his post in how many hours from his last post
    because i want to restrict him if he has 24 hours for posting and he has post in first 10 hours he can't post in i next 14 hours till completing his 24 hours and then again i can allo w him for next post
    You don't need two posts to calculate that. The query I posted will do what you want.. you just need to check the output from the query - if it's 0, then the user hasn't posted anything in the current 24 period so you can allow him to post. If the value is 1, then the user has posted, and should not be allowed to post again.

    Edit: In any case, when a user first signs up at your site, he won't have any posts, so whatever method you use has to work for this situation too.

  8. #8
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    will u little elaborate data structure what are you using in this query ?
    i mean what values table structure you are using so i can make my accordingly.

  9. #9
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by realcoder View Post
    will u little elaborate data structure what are you using in this query ?
    i mean what values table structure you are using so i can make my accordingly.
    Don't you have your own DB tables already set up? It would be easier to adapt my query to your DB, rather than the other way around.

  10. #10
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i have my tables but infact i want to know the that what values you are taking in you query for my easy understanding . moreover i show you my query what i am using
    i have two tables which names are
    LINK
    MSN_USERS

    link is the table where user posted data save with timestamp time,id & userid
    msn_users is the table where users all signup data save including his signup date id and other needed information.
    i used your query but thats giving me wrong output
    however users has post in last 24 hours but that's giving 0 output ?why? whats mistake in my query

    Code:
    $que1 = "SELECT count(link.id) as total
    FROM link, msn_users 
    WHERE link.userid = msn_users.id 
    AND link.time > CONCAT( DATE( NOW() ), ' ', TIME(msn_users.date) ) 
    AND user.id = $uid";
    $exe2 = mysql_query($que1);
    if ($exe2 == 0){
        
        echo "you are allowed";
    }

  11. #11
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    mysql_query returns a resource which you then have to process with other functions. In this example, you'd have to do the following:
    PHP Code:
    $que1 "SELECT count(link.id) as total
    FROM link, msn_users 
    WHERE link.userid = msn_users.id 
    AND link.time > CONCAT( DATE( NOW() ), ' ', TIME(msn_users.date) ) 
    AND user.id = 
    $uid";

    $exe2 mysql_query($que1);

    mysql_result($exe20'total');

    if (
    == mysql_result($result0'total')){
        
    // User is allowed to post

    Be aware that the mysql extension is depreciated and will be removed from PHP - you should switch to using the mysqli or PDO extensions.

  12. #12
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    will u describe me that your mentioned two columns
    user.created
    post.created
    storing which format
    because my column in link save timestamp
    but my colum in msn_users save only date
    did this query work ?

  13. #13
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Hi, no for my query to work, your msn_users.date field would have to be DATETIME (or timestamp would do, if we change the query a little) as we need the time that the user joined to calculate the 24 period correctly. So, if a user joins on 2013-08-06 13:46:00, they can only make one post until 2013-08-07 13:46:00, when the next 24 hour period begins.

  14. #14
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this calculate of my every last post ?
    or just first single post after singup?
    because query still not working properly. now i have set datetime in msn_users table but still same output

  15. #15
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my main purpose is to check to check
    for example
    if user signup he get 24 hours for posting
    if he post in first 12 hours then in next 12 hours he will not able to next post but whenever his 24 hours complete again he get 24 hours for next post and again same restriction of 1 post in 24 hours
    and my main problem is here to check the time of after submitting his post that is his 24 hours period completed if not he can't post if yes let him do post

  16. #16
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    If your link.time column is in TIMESTAMP format, you'll need to use the FROM_UNIXTIME function to convert it first:

    Code MySQL:
    SELECT count(link.id) as total
    FROM link, msn_users 
    WHERE link.userid = msn_users.id 
    AND FROM_UNIXTIME(link.time) > CONCAT( DATE( NOW() ), ' ', TIME(msn_users.date) ) 
    AND user.id = $uid

    It might be better to experiment with entering this query directly into something like phpMyAdmin first, to check it's returning the values you expect.

  17. #17
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i try this query and its returning 0 value in phpmyadmin
    however the link i have recently create a post table with recent time.
    i dont think it want to return 0

  18. #18
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Could you post an example row of data from each table?

  19. #19
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i think

    this query working

    Code:
    SELECT count(link.id) as total
    FROM link, msn_users 
    WHERE link.userid = msn_users.id 
    AND link.dtime > CONCAT( DATE( NOW() ), ' ', TIME(msn_users.time) ) 
    AND msn_users.id = userid
    because i have created one 2 colums in both tables with Datetime format..

    but i think its not working with php in that it return wrong value

    with this code
    PHP Code:
    $que1 "SELECT count(link.id) as total
    FROM link, msn_users 
    WHERE link.userid = msn_users.id 
    AND link.dtime > CONCAT( DATE( NOW() ), ' ', TIME(msn_users.time) ) 
    AND msn_users.id = 
    $id";

    $exe2 mysql_query($que1);

    mysql_result($exe20'total');

    if (
    == mysql_result($result0'total')){
       echo 
    "you are allow";


  20. #20
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Oops, I just saw an error in the code I gave you.. I duplicated a line and then changed the wrong one. The code should be:

    PHP Code:
    $que1 "SELECT count(link.id) as total 
    FROM link, msn_users  
    WHERE link.userid = msn_users.id  
    AND link.dtime > CONCAT( DATE( NOW() ), ' ', TIME(msn_users.time) )  
    AND msn_users.id = 
    $id"

    $exe2 mysql_query($que1); 

    if (
    == mysql_result($exe20'total')){ 
       echo 
    "you are allow"


  21. #21
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hii one more
    before this what i was using for showing remaining 24 hours in second . but using your query how will i get remaining time

    i was using this query but it was not useful in sense that when user posts once it start his time from 24 hours from the same time he post but i want 24 hours time after completing his last 24 hours

    Code:
    $que = mysql_query("SELECT TIMESTAMPDIFF(SECOND,time,NOW()) AS 'Diff' FROM link where userid='$id' order by time desc limit 1");
    while($row=mysql_fetch_array($que))
    
    
    
    {
    $re = $row['Diff'];
    $hour = "86400";
    $diff = $hour - $re ;
    
    if($diff <= 0)
    {
    echo "your time has been over";
    exit;
    }
    this is the query which was returning me times in seconds from last post.
    But how can i do this using your query
    for example whenever user next time post time start i can calculate 24 hours limit for posting ?

  22. #22
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Try this:

    PHP Code:
    $sql "SELECT CONCAT( DATE( NOW() ), ' ', TIME(msn_users.time) ) AS period_end
    FROM msn_users
    WHERE id = 
    $id";

    $result mysql_query($sql); 
    $datetime mysql_result($result0'period_end'); 

    $period_end = new DateTime($datetime);
    $now = new DateTime();

    if (
    $period_end $now) {
        
    $period_end->add(new DateInterval('P1D'));
    }

    $interval $now->diff($period_end);

    echo 
    'Time until you can post again: ' $interval->format('H:I:S'); 
    I think it's easier to do the calculations in PHP in this case. You could do them in the query, but the SQL would probably drive you mad if you look at it for too long

  23. #23
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is not working its giving out
    Time until you can post again: H:I:S

  24. #24
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by realcoder View Post
    this is not working its giving out
    Time until you can post again: H:I:S
    Oops, sorry I made a mistake.. it should be:
    PHP Code:
    $interval->format('%H:%I:%S'); 

  25. #25
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hii i am in little confusion
    your one query is saying
    Time until you can post again: 08:03:09

    but your other query saying
    You are allow

    this is the different output of your both queries ? why


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
  •