What would be the best way to store data [mysql]
#1

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

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

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

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)