Mysql loop with variable increment

I added a new row to the table, tracking the number of the game in the round, so it will have values ​​1,2,3,4 .... when the round ends, it will reset to 1, etc.

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

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

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

+7
php mysql
source share
1 answer

Read the manual Defined Variables in mysql

 SET @x := 1; -- Define a variable INSERT INTO events (game_nr) values (@x := @x + 1) 
+3
source share

All Articles