SA-MP Forums Archive
[MySql] Creating multiple rows at once. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [MySql] Creating multiple rows at once. (/showthread.php?tid=467249)



[MySql] Creating multiple rows at once. - Unri - 02.10.2013

Hello. Is it possible to create multiple rows at once/with one query. The rows have to be with their default vaules, only different IDs ofcourse. Something like
Код:
INSERT INTO `entrances` (`id`) VALUES between (1) and (1000);
if it even exists.


Re: [MySql] Creating multiple rows at once. - iZN - 02.10.2013

pawn Код:
format(query, sizeof(query), "INSERT INTO `entrances`(id, var1) VALUES(0, '%d', '%d',)" id, var);



Re: [MySql] Creating multiple rows at once. - Unri - 02.10.2013

I mean a sql query. Not needed for script. I just want to create tons of default rows from id 1 to id 1000.


Re: [MySql] Creating multiple rows at once. - -=Dar[K]Lord=- - 02.10.2013

You can just put the statement in a loop for executing the statement how much times you want ...


Re: [MySql] Creating multiple rows at once. - Unri - 02.10.2013

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
You can just put the statement in a loop for executing the statement how much times you want ...
If I knew how to create a loop, i wouldnt ask this question.


Re: [MySql] Creating multiple rows at once. - -=Dar[K]Lord=- - 02.10.2013

Quote:
Originally Posted by Unri
Посмотреть сообщение
If I knew how to create a loop, i wouldnt ask this question.
Fine , just give me the table name , the var you want to set , and other things which you want to put in that creation of rows once at a time


Re: [MySql] Creating multiple rows at once. - Unri - 02.10.2013

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
Fine , just give me the table name , the var you want to set , and other things which you want to put in that creation of rows once at a time
Table name is "entrance". All i need is to have rows from id 1 to id 1000 with default values. Nothing more. Just make it insert id 1, id 2, id 3.


Re: [MySql] Creating multiple rows at once. - -=Dar[K]Lord=- - 02.10.2013

hmm so ... the ids are like
id 1 , id 2 , id 3 are coloums and 1 - 1000 are rows?

EDIT: Whats the default Value?


Re: [MySql] Creating multiple rows at once. - Unri - 02.10.2013

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
hmm so ... the ids are like
id 1 , id 2 , id 3 are coloums and 1 - 1000 are rows?

EDIT: Whats the default Value?
Each row has its own id. 555th row will have id = 555. 839th row will have id = 839. Default values are the ones specified for each column in table options.


Re: [MySql] Creating multiple rows at once. - -=Dar[K]Lord=- - 02.10.2013

fine .... i will give you the loop code fix it accordingly

pawn Код:
new string[256];
for(new i = 1; i <= 1000; i++)// Will take a loop throught 1000 numbers
{
    format(string,sizeof(string),"INSERT INTO entrance(id) VALUES(%d)",i);//will set the number as per as loop goes
    mysql_query(string);//will do the mysql query part
}