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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:25:25+00:00 2026-05-31T04:25:25+00:00

Without using PHP or anything. Is there a way to do something like this:

  • 0

Without using PHP or anything. Is there a way to do something like this:

UPDATE myTable SET var1 = var1 + 1 IF var1 < 5 ELSE var1 = 0 WHERE [WHERE clause]

Never really done any IF mySQL things so a little unsure?

So the result would be that the variable would never be higher than 5 and reset to 0 if its at 5 when incremented.

TIA

  • 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-31T04:25:26+00:00Added an answer on May 31, 2026 at 4:25 am

    Either use IF()

    UPDATE MyTable SET var1 = IF(var1 < 5, var1 + 1, 0) WHERE id = 1;
    

    or in this case, simpler, just use the modulo operator

    UPDATE MyTable SET var1 = (var1 + 1) MOD 6 WHERE id = 1;
    

    Edit: Yes, I realize that if the range starts outside of 0..5 the latter one will not work, I just figured the intent was to keep the numbers between 0 and 5 inclusive. If I’m wrong about that, keep to the first one 🙂

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

Sidebar

Related Questions

What is the best way to password protect folder using php without a database
Using Apache 2.2 and PHP 5, what's the best way to run PHP without
Without using Javascript, is there a way to make a CSS property toggle on
I am trying to use PHP session without using cookies. I have enabled session.use_trans_sid
In php how can I access an array's values without using square brackets around
How can we separate Logic from presentation without using any template engine (traditional php-not
I am using a login system. When I navigate to comments/index.php without logging in,
Without using any third party program to do this (i.e. without VMware ThinApp, U3
I currently have this code in the page/div when you load it without anything
I was wondering if there is a way to use php to return the

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.