how to increment login days while log in by mysql UPDATE?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
infomamun
Forum Contributor
Posts: 102
Joined: Mon Dec 28, 2009 7:48 pm

how to increment login days while log in by mysql UPDATE?

Post by infomamun »

have following structure in a mysql table:

Code: Select all

id || username || lastlogin || days
1  || user-xyz || 2013-04-29 || 0
The above 'lastlogin' column is date column and 'days' column is int(3) column. What I want to do, while a user will login, lastlogin column will be updated everytime as usual. At the same time, the 'days' column will be incremented if the login date (when the user is logging in) is greater than the date of lastlogin column. If the user is logging in at the same day again, the days will be same (will not be updated).

What will be the mysql query in this case?

The query format will be something like this:

Code: Select all

$logindate = date("Y-M-D",time());
update table set lastlogin=$logindate, days=days+1 if $logindate>lastlogin WHERE usename=user-xyz
Any help will be appreciated.

Regards
Post Reply