Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql loop with variable incrementing

Tags:

php

mysql

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?

like image 980
Timothy Coetzee Avatar asked May 18 '15 06:05

Timothy Coetzee


1 Answers

Read manual Defined Variables in mysql

SET @x := 1; -- Define a variable
INSERT INTO events (game_nr) values (@x := @x + 1)
like image 184
Saty Avatar answered Oct 14 '22 00:10

Saty