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 7074541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:04:13+00:00 2026-05-28T06:04:13+00:00

I have users visiting the site. The user can do a bunch of different

  • 0

I have users visiting the site. The user can do a bunch of different actions. I’d like a counter to count the amount of times the user does that action. The problem is, it’s per day, it starts over each day.
So the model has, Id, User, Action, Times, Date

I’d like to use this, but I can’t because Action is not a key, and cannot be. None of the other fields can be a key either.

insert into useractions (user, action, times) values (2, 3, 1)
on duplicate key update times = times + 1;
  • 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-28T06:04:13+00:00Added an answer on May 28, 2026 at 6:04 am

    Do you absolutely want to calculate the counter value at the time of inserting the action? It may be simpler to simply keep track of the users and actions with timestamps, like so:

    +--------+----------+---------------------+
    | UserID | ActionID | Time                |
    +--------+----------+---------------------+
    |      1 |        1 | 2012-01-19 14:47:03 |
    |      1 |        2 | 2012-01-19 14:48:12 |
    |      1 |        3 | 2012-01-19 14:48:15 |
    |      2 |        1 | 2012-01-19 14:49:33 |
    |      2 |        1 | 2012-01-18 14:49:42 |
    

    And then calculate the daily tallies with a query:

    SELECT UserID,
           ActionID,
           DATE(Time) AS Date,
           COUNT(*) AS n
    FROM actions
    GROUP BY UserID,ActionID,Date
    ORDER BY Date,UserID,ActionID;
    
    +--------+----------+------------+---+
    | UserID | ActionID | Date       | n |
    +--------+----------+------------+---+
    |      1 |        2 | 2012-01-17 | 2 |
    |      1 |        3 | 2012-01-17 | 2 |
    |      3 |        2 | 2012-01-17 | 6 |
    |      1 |        1 | 2012-01-18 | 1 |
    |      1 |        2 | 2012-01-18 | 1 |
    |      1 |        3 | 2012-01-18 | 4 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the coordinates of users visiting my site, so I can
I have users that have several objects and can upload images for those objects.
In my web application I will have users, each user will have albums, and
We have a site where the user gets a navigation bar to allow navigation
I have a web site server which do such work like this: The server
I have a form where users can submit sites and say if they work
I have users who are using secure-wave security. Evidently it is some sort of
I have users table. There are three other tables: developers, managers, testers. All of
i have users table and i have posts table i want select from users
I have users who write articles and when they leave there computer for a

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.