• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Saving variables into multiple tables
#1
Wink 
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!
  Reply
#2
(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.
  Reply
#3
So if i want one table for each stat category (probably 50), I need to create 50 querries?
  Reply
#4
(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?
  Reply
#5
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.
  Reply
#6
(2020-12-15, 03:15 PM)Epureanu Wrote: 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.



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.
  Reply
#7
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`...;
Notice the semicolon

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/1047...involved-t
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#8
But how can I use the "id" in the other tables, when it is basically a column in "basic" table?
  Reply
#9
(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...ert_id.asp
Fixed the url^
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply


Forum Jump: