Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:07:18+00:00 2026-06-03T07:07:18+00:00

I have a database full of php time(); stored when a user logs in.

  • 0

I have a database full of php time(); stored when a user logs in.

I know I should have created a value for their username and updated the login count but instead I have a database full of php time(); with their username

Here is how I find the amount of logins for individual users:

<?php
function to_date($timestamp) {
    return date('Y-m-d', $timestamp);
}
$days = array();
$occurences = array();
$zero = array();
$query = mysql_query("SELECT `login_time` FROM `stats` WHERE `userid`='$someuserid' ORDER BY `login_time` ASC");
while($rows = mysql_fetch_array($query)) {
    $days[] = to_date($rows['login_time']);
}
$days[] = to_date(time());
$occurences = array_count_values($days);
$days = array_unique($days);
sort($days);
for($i = 0; $i < count($days); $i++) {
    $difference = isset($days[$i+1]) ? strtotime($days[$i+1]) - strtotime($days[$i]) : 0;
    if($difference > 86400) {
        $difference = ceil(abs($difference/86400));
        $fill = $days[$i];
        for($k = 0; $k < $difference-1; $k++) {
        $fill += strtotime('+1 day', strtotime($fill));
            $zero[] = to_date($fill);
        }
    }
}
echo "[";
for($i = 0; $i < count($zero); $i++) {
    echo "[\"".$zero[$i]."\",0], ";
}
for($i = 0; $i < count($occurences); $i++) {
    if($i == count($occurences)-1)
        echo "[\"".$days[$i]."\",".($occurences[$days[$i]]-1)."]";
    else {
        echo "[\"".$days[$i]."\",".$occurences[$days[$i]]."], ";
    }
}
echo "]";
?>

How could I apply this to all the users and find out who logged in the most for each day in the database? The output is encoded for jqplot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:07:20+00:00Added an answer on June 3, 2026 at 7:07 am
    SELECT
        userid,
        DATE(FROM_UNIXTIME(login_time-MOD(login_time,86400)+1)) as logindate,
        count(*) as logincount
    FROM stats 
    GROUP BY userid, logindate
    

    Use the above query to get all the required data directly from the database and this will help you avoid doing the post processing using PHP

    Additionally, if you would like to get only one record, which have maximum logins in a (any) day, the use the below query with an added SQL wrapper for the above query:

    SELECT * FROM (
        SELECT
            userid,
            DATE(FROM_UNIXTIME(login_time-MOD(login_time,86400)+1)) as logindate,
            count(*) as logincount
        FROM stats 
        GROUP BY userid, logindate
    ) tmptable 
    ORDER BY logincount DESC, logindate DESC LIMIT 1
    

    Let me know if this helped you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database full of items, which should be searchable by any or
I have a database table full of time points and experimental values at those
I have a database full of customer data. It's so big that it's really
I have a database full of small HTML documents and I need to programmatically
I have a database full of text fields that look like this: (paragraph of
I have a database full of two-dimensional data - points on a map. Each
Problem: I have a symfony project with a database full of production data I
I have a database with a table which is full of conditions and error
I have a database table which is full-text indexed and i use the CONTAINS-function
I have a database table full of words. What I would like to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.