Hi there, I am currently working on a browser based game written in PHP. The issue im coming to at the moment is with adding multiple entries to a db table with only one query.
I have a db table called 'user_accounts' where all the users details are stored. In this table is a field called 'powers'. 3 values, 1 = server admin, 2 = game admin, 3 = normal user. Another table called '$db_name'_users where '$db_name' is a unique value to the game. On the server there will be 4 games running in total. Basically I want to add all the users with the power lvl of 1 (so all the server admins) from user_accounts to the dbname_users table. Obviously I can do this manually, but im making an automated installation script, so would like to add them all in one go. I can't use a generic user as the server owner creates the server admins in a previous step in the install script, so would be unique to each application of the game.
here is the first code I tried:
db(__FILE__,__LINE__,"SELECT login_id, login_name, email_address FROM user_accounts WHERE powers = 1");
$server_ads = dbr();
dbn(__FILE__,__LINE__,"INSERT INTO $_POST[_dbname]_users (login_id, login_name, cash, tech, genesis, terra_imploder, alpha, gamma, delta, sn_effect, grav_mine, hornet_mine, leech, email_address) VALUES ('$server_ads[login_id]', '$server_ads[login_name]', '99999999999', '99999999', '999999', '999999', '999999', '999999', '999999', '999999', '999999', '999999', '999999', '$server_ads[email_address]')");
this correctly selected a user who matched the criteria and added it to the correct db table.. however it tried to repeatedly add the same user and as the login_id field is unique I got a duplicate error in the sql.
the next tweak I tried was to put
while($server_ads = dbr())
again this selected the correct user and put it into the right table, however it only added one user, when there are 3 users who match the criteria. Anyone got any ideas?