[Pawn] Saving variables into multiple tables - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10) --- Thread: [Pawn] Saving variables into multiple tables (/showthread.php?tid=1422) |
Saving variables into multiple tables - Epureanu - 2020-12-15 Hi, I am using a mysql saving system, that basically creates a enumerator with variables, but natively they are all saved into one table. I tried to just put a ", 2ndtablename" into the saving and loading query, but I had a feeling that it would save those variables both in the main table and the secondary. I need to save certain variables ONLY to second table. Is there any way on how to do this without running a new query for each table? Thanks! RE: Saving variables into multiple tables - Gforcez - 2020-12-15 (2020-12-15, 01:13 PM)Epureanu Wrote: Hi, I am using a mysql saving system, that basically creates a enumerator with variables, but natively they are all saved into one table. I tried to just put a ", 2ndtablename" into the saving and loading query, but I had a feeling that it would save those variables both in the main table and the secondary. I need to save certain variables ONLY to second table. Is there any way on how to do this without running a new query for each table? Thanks! If I understand your question right, you want to update data in two tables within one query? I don't think that's possible. You have to create seperate queries in order to update two tables of a database. RE: Saving variables into multiple tables - Epureanu - 2020-12-15 So if i want one table for each stat category (probably 50), I need to create 50 querries? RE: Saving variables into multiple tables - Gforcez - 2020-12-15 (2020-12-15, 02:55 PM)Epureanu Wrote: So if i want one table for each stat category (probably 50), I need to create 50 querries? Yes, but you might want to reconsider how you structure the tables for stats. Can you give us an example of those stats and what they look like? RE: Saving variables into multiple tables - Epureanu - 2020-12-15 Settled into categories: basic - password, position of player, his money, etc. kills - kills, deaths, suicides, etc... admin - each admin privileges for certain commands weapon - weapon stats cars - carss tats... etc. So basic, kills, admin, weapon, cars should be tables separated, or else I would have 1000 columns in one table (basic), which would be ridiculous. RE: Saving variables into multiple tables - Gforcez - 2020-12-15 (2020-12-15, 03:15 PM)Epureanu Wrote: Settled into categories: Yes, I would probably make seperate tables for the statistics you have listed here, using the id of the users' account (what you've listed as "basic" stats)?to select and update the players stats. RE: Saving variables into multiple tables - Pinch - 2020-12-15 You can enable mysql option, MULTI_STATEMENTS, (mysql_set_option, toggling the mentioned option (true)) and have multiple MySql queries executed in a single mysql query native. For example Code: INSERT INTO `something`...; INSERT INTO `something else`...; Sorry for the bad example, I don't have a PC at the moment so I can't really write much of an example but I found this (example is using primary keys - you should consider using foreign keys instead): https://stackoverflow.com/questions/10471757/insert-rows-into-multiple-tables-in-a-single-query-selecting-from-an-involved-t RE: Saving variables into multiple tables - Epureanu - 2020-12-15 But how can I use the "id" in the other tables, when it is basically a column in "basic" table? RE: Saving variables into multiple tables - Pinch - 2020-12-15 (2020-12-15, 03:42 PM)Epureanu Wrote: But how can I use the "id" in the other tables, when it is basically a column in "basic" table?This is outside of this subforum's topic, this is more of a SQL topic (SQL is entirely different language, nothing to do with PAWN) You should learn (my)sql basics, https://www.w3schools.com/sql/sql_foreignkey.asp EDIT: Also, you have SQL variable called LAST INSERT ID https://www.w3schools.com/sql/func_mysql_last_insert_id.asp Fixed the url^ |