每天设置一个柜台

For our recent project we need to include a counter based on date.

For example a page view counter for answer.php is set in mysql table called counter.

Daily access to answer.php is limited to 150(page views). the table counter will store each access and when daily allowance 150 is over then it gives a warning that you exceeded your limit and block the display.

But I am not able to figure out how this can be done on daily basis. I mean when the next day starts how the counter can be reset and start from 0.

The curdate function returns the current date, so something similar to this:

$sql = "SELECT count(*) from logintable where 'logindate' = CURDATE()";

I realise your query would probably involve more tables and fields. This is a very simplistic off the top of my head untested reply, I'm not sure it even works. Just thinking out loud here.

You need a table which maps dates to pageviews

The answer from @stefgosselin was the first thing you'd want to do; then if the count was < 150, insert a row. If the count was 150 or more, reject the query and tell them they had reached their threshold.

Is it 150 pages per user??? or total no matter who. If its per user, then it should be as simple as adding a single counter to that user's record and keep increasing each time a countable "request" comes in, and look at that count as needed to prevent results as restricted.

Then, since a user has no way of back-dating his/her requests, at the beginning of each day (even via some trigger), you can just update your table to reset all counts back to zero...

Update UserLoginTable set RequestCount = 0

Done.

You create a table called loginlog (a log of all the logins)

table loginlog
  id integer autoincrement primary key
  user_id integer
  logindate date
  logincount integer

unique key userdate(user_id, logindate)

Next you create a before update trigger on your table

DELIMITER $$

CREATE TRIGGER bu_loginlog_each BEFORE UPDATE ON loginlog FOR EACH ROW
BEGIN
  /*Force an error by selecting from a non-existing table*/
  /*this will prevent the update*/
  IF new.logincount > 150 THEN SELECT * FROM create_error_only_150_logins_allowed
END $$

DELIMITER ;

In your php code do the following:

INSERT INTO loginlog (user_id, logindate, logincount) 
  VALUES ('$user_id',curdate(),1)
  ON DUPLICATE KEY UPDATE logincount = logincount + 1

Test if the insert succeeded.
If the insert/update fails your user has logged in > 150 times and you can refuse the user.

This will only keep one record per user per day. You can even purge past days from the loginlog table after x number of days.