Jump to content
  • 0

Adding multiple SQL Values using insert


Question

Posted

I'm not sure where to start but how to add multiple lines/value on SQL Insert Into.

I want to give rewards to a list of players with 3 different rewards 1 apple, 2 red potions, 30 flywings for example

I have a separate table for rewards to insert the items.

Here is my code:

set .@count, query_sql("SELECT `account_id` FROM `cp_createlog` WHERE `reg_date` BETWEEN '2017-10-24 00:00:00' AND '2017-10-26 23:59:59'", .@account_id);
set .@eventname$ = "Testing";
setarray .@prize[0],14532,14592,14001,16682,2751,12210;
setarray .@pamount[0],3,3,5,1,1,5;
for(set .i, 0; .i < getarraysize(.@count); set .i,.i+1)
for(set .j, 0; .j < getarraysize(.@prize); set .j,.j+1)
for(set .k, 0; .k < getarraysize(.@pamount); set .k,.k+1)
set .@reward$, "( .@account_id[.i], '.@eventname$', .@prize[.j], .@pamount[.k], 0)";
query_sql("INSERT INTO `event_rewards` ( `account_id`, `event_name`, `id`, `amount`, `value` ) VALUES '"+ .@reward$ +"' ");

the .@reward$ stands as the value input to the sql insert value.

how can i make .@reward$ output to something this:

( 200000, 'Testing', 14532, 3, 0),
( 200000, 'Testing', 14592, 3, 0),
( 200000, 'Testing', 14001, 5, 0),
( 200001, 'Testing', 14532, 3, 0),
( 200001, 'Testing', 14592, 3, 0),
( 200001, 'Testing', 14001, 5, 0)

how can I make this possible?

2 answers to this question

Recommended Posts

  • 0
Posted
query_sql("INSERT INTO `event_rewards` ( `account_id`, `event_name`, `id`, `amount`, `value` ) VALUES ( "+.@account_id[.i]+", '"+.@eventname$+"', "+.@prize[.j]+", "+.@pamount[.k]+", 0) ");

 

  • Love 1
  • 0
Posted
9 hours ago, Skorm said:

query_sql("INSERT INTO `event_rewards` ( `account_id`, `event_name`, `id`, `amount`, `value` ) VALUES ( "+.@account_id[.i]+", '"+.@eventname$+"', "+.@prize[.j]+", "+.@pamount[.k]+", 0) ");

 

Thank you!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...