简体   繁体   中英

Count number of logins per day in PHP Timeclock (PHP Mysql)

What are the mysql codes to count the number of logins per day in PHP Timeclock?

timestamp bigint(14) is used and I have no idea how to separate them by date.

How do I count the number of ROWS per day?

Here's the command to create the table info:

CREATE TABLE info (
  fullname varchar(50) NOT NULL default '',
  `inout` varchar(50) NOT NULL default '',
  timestamp bigint(14) default NULL,
  KEY fullname (fullname)
) ENGINE=MyISAM;

Sorry I'm just a newbie trying to understand php and MySQL.

Anyway, I can add either of the two in info table:
timestamp timestamp default NULL, or logindate date default NULL,

Suppose I have this portion of the code saved in a php file, how can I modify it so date or timestamp is inserted in info table everytime a user logs in?

$time = time();
$hour = gmdate('H',$time);
$min = gmdate('i',$time);
$sec = gmdate('s',$time);
$month = gmdate('m',$time);
$day = gmdate('d',$time);
$year = gmdate('Y',$time);
$tz_stamp = mktime ($hour, $min, $sec, $month, $day, $year);

    if (strtolower($ip_logging) == "yes") {
        $query = "insert into ".$db_prefix."info (fullname, `inout`, timestamp, notes, ipaddress) values ('".$fullname."', '".$inout."', 
                  '".$tz_stamp."', '".$notes."', '".$connecting_ip."')";
    } else {
        $query = "insert into ".$db_prefix."info (fullname, `inout`, timestamp, notes) values ('".$fullname."', '".$inout."', '".$tz_stamp."', 
                  '".$notes."')";
    }

    $result = mysql_query($query);

Since it's a BIGINT (why, btw?) I assume it's a UNIX Timestamp. I haven't tested this, but something along the lines of this should work:

SELECT DATE(FROM_UNIXTIME(timestamp)) AS date, COUNT(*)
FROM info
GROUP BY date

You might wanna just store the timestamp as a TIMESTAMP column type, and then just use DATE(timestamp) to group by date.

仅添加一列日期(没有时间)并使用此:

SELECT COUNT(*), dateColumn FROM info WHERE fullname='{The user full name}' GROUP BY dateColumn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM