1

Is there a way to add 1 to an integer column on the SELECT statement? Something like:

$result = mysql_query('SELECT (counter + 1) from table...

Thanks.

3
  • Yes, what you have will work correctly. Did you try it? Commented Jan 15, 2012 at 13:29
  • If you mean you want to increment the actual column value in the database by the select: luckily, this is not possible. Commented Jan 15, 2012 at 13:31
  • Yes, tried it. I need the AS alias -- see @Michael 's answer below. Commented Jan 15, 2012 at 13:45

1 Answer 1

1
SELECT (counter + 1) AS counter FROM table;

Just be sure to specify a column alias (AS counter) or it will be more difficult to use mysql_fetch_assoc()

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Worked with AS. Thanks @Michael!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.