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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:13:39+00:00 2026-05-30T07:13:39+00:00

I will try explaining the problem in as much detail as I can, without

  • 0

I will try explaining the problem in as much detail as I can, without explaining the application itself.

I have a MySQL table that records time when a message was sent, and if it was read or unread.
Now I need to make a column in this table that gives message a status according to the interval of time it was unread.

For example, if message was unread for:
1h - it gets status of "1";
1day - status of "2";
2days - status of "3";
3days - status of "4";
7days and more - status of "5".

So lets say I have a message that was sent 13:20 and it is unread, it has a status of “NULL”. I need it to have a status of “1” at 14:20 and a status of “2” next day at 13:20.

Now I can think of a couple of options, but they involve Crone jobs every minute, and/or masses of calculating. My site is fast growing and I would like to find a most optimal and scalable option. Maybe there is some inside MySQL option, like triggers or something.

Any help is appreciated <3

  • 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-30T07:13:40+00:00Added an answer on May 30, 2026 at 7:13 am

    It seems like this may be more appropriately handled in the query that retrieves the messages rather than something that updates the table continuously.

    You can either compute the status in the application after retrieving the messages, or return a computed status field from the query itself:

    SELECT
      user,
      from,
      subject,
      time,
      created,
      read,
      IF(NOW() - INTERVAL 7 DAY > created, 5,
        IF(NOW() - INTERVAL 3 DAY > created, 4,
          IF(NOW() - INTERVAL 2 DAY > created, 3
            IF(NOW() - INTERVAL 1 DAY > created, 2
              IF(NOW() - INTERVAL 1 HOUR > created, 1
                0
              )
            )
          )
        )
      )
    FROM messages
    WHERE user = 'foo'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will try my best to explain this. I have an application that show
I will try to give as much detail as I can. I am creating
I have a problem and I will try to explain the issue: I have
I will try and ask my question clearly... I have three tables that each
I will try to expand my problem: I have a link: <a href=# onClick=Display();
I will try to explain my problem clearly: I have two tables: document and
I will try to make my problem as clear as I can, so please
I will try to make this as clear as I can, but if you
I will try to be as clear as possible because I can't get anybody
I will try to keep this as simple as possible. I have a rather

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.