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

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

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.

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

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):

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.

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.

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.

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

$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";
}

mysql_query returns a resource which you then have to process with other functions. In this example, you’d have to do the following:


$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($exe2, 0, 'total');

if (0 == mysql_result($result, 0, '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 [fphp]mysqli[/fphp] or [fphp]PDO[/fphp] extensions.

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 ?

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.

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

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

If your link.time column is in TIMESTAMP format, you’ll need to use the FROM_UNIXTIME function to convert it first:

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.

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

Could you post an example row of data from each table?

well i think

this query working

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

$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($exe2, 0, 'total');

if (0 == mysql_result($result, 0, 'total')){
   echo "you are allow";
}

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:


$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 (0 == mysql_result($exe2, 0, 'total')){
   echo "you are allow";
}