21.09.2012, 15:23
Hello,
Here is a part of my code to create an account,
It works all fine, except that 'part 2' is slower then 'part 3', so this means that the USER_ID's which will set in the query's at part 3 are not correct because he isn't fininshed with getting the USER_ID from the plr_account table.
I guess because it uses threads.
But the question is,
Can I also replace the query's in part 3 to query's that insert the USER_ID and USER_NAME from the plr_account.
So I can remove part 2.
I know it's possible, but everything I found at the internet is just wierd lol.
Something know how it works?
If you don't understand this , no problem then the question is: How to insert data from another table inside a table in one query.
Here is a part of my code to create an account,
Code:
public FUNCTION_CreatePlayer(playerid) { // part 1 >> format(p[VAR_ACC_STRING],STR_MEDIUM,"INSERT INTO `plr_account` (`USER_NAME`, `USER_PASS`) VALUES ('%s', SHA1('%s'))",STOCK_PlayerClientName(playerid),p[VAR_ACC_PASSWORD]); mysql_query_nodata(p[VAR_ACC_STRING]); // part 2 >> format(p[VAR_ACC_STRING],STR_SMALL,"SELECT `USER_ID` FROM `plr_account` WHERE `USER_NAME`= '%s'",STOCK_PlayerClientName(playerid)); mysql_function_query(VAR_SQL_CONNECTION, p[VAR_ACC_STRING], true, "FUNCTION_ReturnUserID", "i", playerid); // part 3 >> format(p[VAR_ACC_STRING],STR_MEDIUM,"INSERT INTO `plr_house` (`USER_ID`, `USER_NAME`) VALUES (%d, '%s')",p[VAR_ACC_ID],STOCK_PlayerClientName(playerid)); mysql_query_nodata(p[VAR_ACC_STRING]); format(p[VAR_ACC_STRING],STR_MEDIUM,"INSERT INTO `plr_items` (`USER_ID`, `USER_NAME`) VALUES (%d, '%s')",p[VAR_ACC_ID],STOCK_PlayerClientName(playerid)); mysql_query_nodata(p[VAR_ACC_STRING]); format(p[VAR_ACC_STRING],STR_MEDIUM,"INSERT INTO `plr_jobs` (`USER_ID`, `USER_NAME`) VALUES (%d, '%s')",p[VAR_ACC_ID],STOCK_PlayerClientName(playerid)); mysql_query_nodata(p[VAR_ACC_STRING]); format(p[VAR_ACC_STRING],STR_MEDIUM,"INSERT INTO `plr_logs` (`USER_ID`, `USER_NAME`) VALUES (%d, '%s')",p[VAR_ACC_ID],STOCK_PlayerClientName(playerid)); mysql_query_nodata(p[VAR_ACC_STRING]); print("3-"); p[VAR_ACC_REG_STEP] = 1; return 1; }
I guess because it uses threads.
But the question is,
Can I also replace the query's in part 3 to query's that insert the USER_ID and USER_NAME from the plr_account.
So I can remove part 2.
I know it's possible, but everything I found at the internet is just wierd lol.
Something know how it works?
If you don't understand this , no problem then the question is: How to insert data from another table inside a table in one query.