7

I added a new row to my table, keeping track of the game number in the round, thus it will have values 1,2,3,4.... when round ends it will be reset to 1 etc

it will be pretty simple to code this with php or similar just doing

$x=1++
while(round == 1){
INSERT INTO events (game_nr) values ('$x')
$x++
}

Is there something similar I can use as the above code on a mysql db using only mysql?

1
  • may be you are searching for "procedures" in mysql. Commented May 18, 2015 at 6:07

1 Answer 1

3

Read manual Defined Variables in mysql

SET @x := 1; -- Define a variable
INSERT INTO events (game_nr) values (@x := @x + 1)
Sign up to request clarification or add additional context in comments.

2 Comments

beware this may not give you what you want if you expect some sort of ordering to the numbers
Thanks!! Should I put a WHERE clause here aswell like SET @x := 1; -- Define a variable INSERT INTO events (game_nr) values (@x := @x + 1) WHERE round='1'

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.