Help (MySQL)...
#1

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.
Reply
#2

Using sscanf arrays, first you extract the string from database then use this
PHP код:
sscanf(string,"p<|>a<i>[145]",pInfo[playerid][jItem]); 
Reply
#3

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?
Reply
#4

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.
Reply
#5

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
Reply
#6

Up question
Reply
#7

Up!
Reply
#8

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 `TypeFROM `ItemsWHERE `UID` = <user_id
Code:
PHP код:
OnLoad()
{
    for (new 
icache_get_rows_count(); ji++)
    {
        
// 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 
ilimit i++)
    {
        
// do stuff
    
}

You can use Username instead of UID in case you want string matching. But i recommend UID.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)