SA-MP Forums Archive
What would be the best way to store data [mysql] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What would be the best way to store data [mysql] (/showthread.php?tid=583402)



What would be the best way to store data [mysql] - PizzaPuntjes - 28.07.2015

I want to script a shop where people can buy different items, now I know how to do this buy I am wondering what would be the best way to store wether someone has bought this item.

Would I just create another table with structure 1 (found below) and fetch all rows of that player or should I use structure 2?

structure 1: bought_items: player - itemid
structure 2: bought_items: player - item1 - item2 - etc...

Thanks for all responses!


AW: What would be the best way to store data [mysql] - Kaliber - 28.07.2015

You can do it like an smart ass:

PHP код:
enum e_Items (<<=1)
{
    
Hat 1,
    
Shirt,
    
Bag,
    
Bike,
    
Shit //and so on...you can store 32 Items in this
};
new 
e_Items:Items[MAX_PLAYERS];
//Set the item:
Items[playerid] |= Hat//Here he has an Hat
//To reset it:
Items[playerid] &= ~Hat;
//To check if he has a hat:
if(Items[playerid] & Hat)
{
    
//Here he has it
}
//So just save Items[playerid] as int (name: item)
//And to load it:
Items[playerid] = e_Items:item//int is the variable for the loaded item 
Greekz


Re: What would be the best way to store data [mysql] - PizzaPuntjes - 28.07.2015

Oh wow, you really have no idea how this helps me.. Thanks A LOT.


AW: Re: What would be the best way to store data [mysql] - Kaliber - 28.07.2015

Quote:
Originally Posted by PizzaPuntjes
Посмотреть сообщение
Oh wow, you really have no idea how this helps me.. Thanks A LOT.
I editet the Loading Methode...use this


Re: AW: What would be the best way to store data [mysql] - Vince - 28.07.2015

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
PHP код:
//This string you save in the mysql database as items 
What?

Just store the integer and read it back out again. Couldn't be simpler.


Re: What would be the best way to store data [mysql] - Lorenc_ - 28.07.2015

Quote:
Originally Posted by PizzaPuntjes
Посмотреть сообщение
I want to script a shop where people can buy different items, now I know how to do this buy I am wondering what would be the best way to store wether someone has bought this item.

Would I just create another table with structure 1 (found below) and fetch all rows of that player or should I use structure 2?

structure 1: bought_items: player - itemid
structure 2: bought_items: player - item1 - item2 - etc...

Thanks for all responses!
I would do it like this:

Two tables:

`items` (`id`, `item_name`, ...)
`bought_items` (`player`, `item_id`, ...)

This saves you the effort of having to create a new column every time you introduce a new item which is so much better, believe me.

I would advise using account ids in this instance, because if a user changes their name there would be no need to change the player name on the table (if you are using the player name).


AW: Re: AW: What would be the best way to store data [mysql] - Kaliber - 28.07.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
What?

Just store the integer and read it back out again. Couldn't be simpler.
Oh yes, you're right.

Well actually i saved it as string, because of the zeros infront of the first 1.

So you have everytime 32 Bits...and it looks better

But you're right, you can do this only with ints...


Re: What would be the best way to store data [mysql] - PizzaPuntjes - 28.07.2015

Thanks for all responses, I am already using account ids but I just wrote player as quick example :P


Re: What would be the best way to store data [mysql] - PizzaPuntjes - 02.08.2015

Hello, i was trying out and trying to learn the code but this is the result when printing the following stuff

Код:
	pItems[0] |= Hat;
	pItems[0] |= Scarf;
	
	printf("C: %i", pItems[0]);

result: C: 1
I do not understand how it would see 2 items being toggled as true.