Help (MySQL)... -
Unrea1 - 04.10.2016
I developed a code which the variable "items" has a capacity to store 145 items, which I made the following code to quickly save the items (which by the way, I do not know if this is the fastest way to list all items , I saw something out there regarding the use of sscanf but not quite understand .. so I opted for this method)
Код:
for(new items = 0; items < MAX_ITEMS; items++)
{
format(string, sizeof(string), "%i|',",
pInfo[playerid][jItem][items]);
}
mysql_format(mysql, query, sizeof(query), "\
UPDATE `users` SET `Items`='%s' WHERE `Nombre` = '%s'",
string,
GetName(playerid));
mysql_tquery(mysql, query, "", "");
The question is simple, how would it be to load all items ?, and I'm using the symbol "|" to separate values and power load, the detail is that I can not assign each value to "pInfo[playerid][jItem][...]", without more, a greeting.
Re: Help (MySQL)... -
PrO.GameR - 04.10.2016
Using sscanf arrays, first you extract the string from database then use this
PHP код:
sscanf(string,"p<|>a<i>[145]",pInfo[playerid][jItem]);
Re: Help (MySQL)... -
Unrea1 - 04.10.2016
Quote:
Originally Posted by PrO.GameR
Using sscanf arrays, first you extract the string from database then use this
PHP код:
sscanf(string,"p<|>a<i>[145]",pInfo[playerid][jItem]);
|
In the case of the saved, okay well or sscanf ?, also apply if any.., as it would be?
Re: Help (MySQL)... -
Vince - 05.10.2016
Bad. A field in SQL should NEVER store more than one value. A delimited list like that is simply not done. Especially if you have 145 items. This should all be moved to a separate table where you have
two columns: userid and itemid. Then you can make as many rows as you like.
Respuesta: Re: Help (MySQL)... -
Unrea1 - 23.10.2016
Quote:
Originally Posted by Vince
Bad. A field in SQL should NEVER store more than one value. A delimited list like that is simply not done. Especially if you have 145 items. This should all be moved to a separate table where you have two columns: userid and itemid. Then you can make as many rows as you like.
|
Mmm, you suggest that you create table by table in the database and upload them one by one via code, since this would be the way more "optimized" ?, My idea is to try you accommodate in a table but seeing that in this way save as chain and load it as such, it is slower ... If that's the case, to go faster .., I have to do what you say?
Thanks for answering
Respuesta: Help (MySQL)... -
Unrea1 - 24.10.2016
Up question
Respuesta: Help (MySQL)... -
Unrea1 - 26.10.2016
Up!
Re: Help (MySQL)... -
Gammix - 26.10.2016
Here is table structure representation:
PHP код:
Items
ID - INTEGER - PRIMARY_KEY
Type - INTEGER
UID - INTEGER - FOREIGN KEY
Users
ID - INTEGER - PRIMARY_KEY
...
So to count all items owned by a user:
PHP код:
SELECT `Type` FROM `Items` WHERE `UID` = <user_id>
Code:
PHP код:
OnLoad()
{
for (new i, j = cache_get_rows_count(); i < j; i++)
{
// do stuff
}
}
If you have a max item limit, say
#define MAX_ITEMS (10), the for loop will be:
PHP код:
OnLoad()
{
new limit = cache_get_rows_count();
if (limit > MAX_ITEMS)
limit = MAX_ITEMS;
for (new i; i < limit ; i++)
{
// do stuff
}
}
You can use
Username instead of
UID in case you want string matching. But i recommend UID.