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

  • Home
  • SEARCH
  • 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 6790673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:45:11+00:00 2026-05-26T17:45:11+00:00

I’ve got the following MySQL query: SELECT concat(‘<a target=_new href=%%WWWROOT%%/course/user.php?id=1&user=’, u.id, ‘&mode=alllogs>’, u.firstname ,’

  • 0

I’ve got the following MySQL query:

SELECT concat('<a target="_new" href="%%WWWROOT%%/course/user.php?id=1&user=',
              u.id,
              '&mode=alllogs">',
              u.firstname ,' ',
              u.lastname,'</a>') AS Username, 
       count(*) AS logins ,
       (SELECT count(*) 
        FROM mdl_log 
        WHERE userid = l.userid 
        GROUP BY userid) AS Activity 
FROM mdl_log AS l 
JOIN mdl_user AS u ON l.userid = u.id 
WHERE action LIKE '%login%' 
GROUP BY userid 
ORDER BY Activity DESC 
INTO OUTFILE '/tmp/Total_Logins_With_Total_Activity.txt';

I want to extend this so that I can results based on a data range, say 365 days for instance.

So I’m thinking I can alter the above query to select the ‘time’ field from the mdl_logs table and covert that to days (Its a unix timestamp) and then only select when the time is within the last 365 day period. Any help appreciated.

The mdl_log table has the following structure:

+--------+------------------+------+-----+---------+----------------+
| Field  | Type             | Null | Key | Default | Extra          |
+--------+------------------+------+-----+---------+----------------+
| id     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| time   | int(10) unsigned | NO   | MUL | 0       |                |
| userid | int(10) unsigned | NO   | MUL | 0       |                |
| ip     | varchar(15)      | NO   |     |         |                |
| course | int(10) unsigned | NO   | MUL | 0       |                |
| module | varchar(20)      | NO   |     |         |                |
| cmid   | int(10) unsigned | NO   | MUL | 0       |                |
| action | varchar(40)      | NO   | MUL |         |                |
| url    | varchar(100)     | NO   |     |         |                |
| info   | varchar(255)     | NO   |     |         |                |
+--------+------------------+------+-----+---------+----------------+

The mdl_user table looks like:

+---------------+---------------------+------+-----+---------+----------------+
| Field         | Type                | Null | Key | Default | Extra          |
+---------------+---------------------+------+-----+---------+----------------+
| id            | int(10) unsigned    | NO   | PRI | NULL    | auto_increment |
| auth          | varchar(20)         | NO   | MUL | manual  |                |
| confirmed     | tinyint(1)          | NO   | MUL | 0       |                |
| policyagreed  | tinyint(1)          | NO   |     | 0       |                |
| deleted       | tinyint(1)          | NO   | MUL | 0       |                |
| mnethostid    | bigint(10)          | NO   | MUL | 0       |                |
| username      | varchar(100)        | NO   |     |         |                |
| password      | varchar(32)         | NO   |     |         |                |
| idnumber      | varchar(255)        | NO   | MUL |         |                |
| firstname     | varchar(100)        | NO   | MUL |         |                |
| lastname      | varchar(100)        | NO   | MUL |         |                |
| email         | varchar(100)        | NO   | MUL |         |                |
| emailstop     | tinyint(1) unsigned | NO   |     | 0       |                |
| icq           | varchar(15)         | NO   |     |         |                |
| skype         | varchar(50)         | NO   |     |         |                |
| yahoo         | varchar(50)         | NO   |     |         |                |
| aim           | varchar(50)         | NO   |     |         |                |
| msn           | varchar(50)         | NO   |     |         |                |
| phone1        | varchar(20)         | NO   |     |         |                |
| phone2        | varchar(20)         | NO   |     |         |                |
| institution   | varchar(40)         | NO   |     |         |                |
| department    | varchar(30)         | NO   |     |         |                |
| address       | varchar(70)         | NO   |     |         |                |
| city          | varchar(20)         | NO   | MUL |         |                |
| country       | varchar(2)          | NO   | MUL |         |                |
| lang          | varchar(30)         | NO   |     | en_utf8 |                |
| theme         | varchar(50)         | NO   |     |         |                |
| timezone      | varchar(100)        | NO   |     | 99      |                |
| firstaccess   | int(10) unsigned    | NO   |     | 0       |                |
| lastaccess    | int(10) unsigned    | NO   | MUL | 0       |                |
| lastlogin     | int(10) unsigned    | NO   |     | 0       |                |
| currentlogin  | int(10) unsigned    | NO   |     | 0       |                |
| lastip        | varchar(15)         | NO   |     |         |                |
| secret        | varchar(15)         | NO   |     |         |                |
| picture       | tinyint(1)          | NO   |     | 0       |                |
| url           | varchar(255)        | NO   |     |         |                |
| description   | text                | YES  |     | NULL    |                |
| mailformat    | tinyint(1) unsigned | NO   |     | 1       |                |
| maildigest    | tinyint(1) unsigned | NO   |     | 0       |                |
| maildisplay   | tinyint(2) unsigned | NO   |     | 2       |                |
| htmleditor    | tinyint(1) unsigned | NO   |     | 1       |                |
| ajax          | tinyint(1) unsigned | NO   |     | 1       |                |
| autosubscribe | tinyint(1) unsigned | NO   |     | 1       |                |
| trackforums   | tinyint(1) unsigned | NO   |     | 0       |                |
| timemodified  | int(10) unsigned    | NO   |     | 0       |                |
| trustbitmask  | int(10) unsigned    | NO   |     | 0       |                |
| imagealt      | varchar(255)        | YES  |     | NULL    |                |
| screenreader  | tinyint(1)          | NO   |     | 0       |                |
+---------------+---------------------+------+-----+---------+----------------+
  • 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-05-26T17:45:11+00:00Added an answer on May 26, 2026 at 5:45 pm

    Queries are likely to perform better if you compare the unconverted table column to a value of its own type – like so:

    SELECT concat('<a target="_new" href="%%WWWROOT%%/course/user.php?id=1&user=',
                  u.id,
                  '&mode=alllogs">',
                  u.firstname ,' ',
                  u.lastname,'</a>') AS Username, 
           count(*) AS logins ,
           (SELECT count(*) 
            FROM mdl_log 
            WHERE userid = l.userid 
            GROUP BY userid) AS Activity 
    FROM mdl_log AS l 
    JOIN mdl_user AS u ON l.userid = u.id 
    WHERE l.action LIKE '%login%' AND
          l.time >= unix_timestamp(adddate(date(now()),interval -365 day)
    GROUP BY userid 
    ORDER BY Activity DESC 
    INTO OUTFILE '/tmp/Total_Logins_With_Total_Activity.txt';
    

    You could use interval -1 year, if you wanted to take account of leap years.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string

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.