structure for inventory database
#1

Hello, What do you guys think is the most efficient way of storing data for an inventory system?
The way I'm doing it right now is just creating a new row in the inventory db for each object of each player. The problem with that is that if the players own a lot of items it's going to take a long time for the code to loop through all the rows.

PHP код:
for(new i<= GetLastInvID(playerid); i++)
{
//this code checks if i, which is the id of the object in the database, is owned by the player. If yes the object is given to the player

I tried to make something like GetLastInvID(playerid), which gets the last id for a specific player to reduce the amount of iterations. But that probably won't make a big difference.

How can I improve my code and/or database structure to get the fastest results?
Reply
#2

Hey, this might be of interest to you: https://sampforum.blast.hk/showthread.php?tid=238844
Reply
#3

If you use pagination you should be fine. Show twenty items per page or so. Additionally you can group by type or purpose or so.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
If you use pagination you should be fine. Show twenty items per page or so. Additionally you can group by type or purpose or so.
But if for example I have an object with ID 1000 in the database the code will have to loop from 0 to 1000, which takes a lot of time. So isn't there a way to make it faster, maybe foreach?
Reply
#5

Quote:
Originally Posted by PeanutButter
Посмотреть сообщение
But if for example I have an object with ID 1000 in the database the code will have to loop from 0 to 1000, which takes a lot of time. So isn't there a way to make it faster, maybe foreach?
If you're using SQL then you shouldn't have a problem.
Reply
#6

You just need some clever queries that limit the result to exactly what you need.

If you use MySQL, LIMIT is the very simple and effective solution that solves your problem entirely. You'll just need to insert a page number and keep track of the total items.

If you use SQL, it may get a bit complicated if you want it very efficiently.

Anyway, if you need more help with that, there are plenty of tutorials everywhere - especially about MySQL pagination. Alternatively give us a bit more information (MySQL or SQL, etc).
Reply
#7

Alright thanks for the help guys
+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)