Monkuar Posted May 20, 2013 Share Posted May 20, 2013 (edited) I need some help/idea on how to store user's items in their inventory. Like you see on mmorpg's/etc. The inventory page looks like this: Let's say I have 5 items in my mysql row. Long Sword Baseball Cap Magic Primer Magic Seal Scrolls Iron Belt All stores in my mysql row. Taking up 5 rows. How would I spit out these items into the users inventory page based on location? (Order/Sort) and which box they moved it to? Let's say, they want to put Iron Belt to the bottom right box, how would I store that in mysql? Would I need a new table like users_inventoryslots or something to store what each items location is on each user's inventory? It's really confusing, hope u can help, thanks! Again, so if the Iron Belt is moved to the buttom right box. Let's say they move the Magic Primer item to the bottom left box, how to store information like this? (for each individual item must be stored server side.. not sure how with mysql) I know the mysql functions to update/insert and php code, but not sure how to actually have the items show up on each boxes in people's inventory, this is where my brain is stuck at. Edited May 20, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/ Share on other sites More sharing options...
BorysSokolov Posted May 20, 2013 Share Posted May 20, 2013 This could be done using JavaScript; You could assign a unique ID to all the slots in the inventory, and then load the items using a JS file that would fetch the data from a PHP file with access to the database. On a side note, I don't think you'd need to store the exact position of each item in the database. If you'd need to know in which slot an item is located, you could find out with a simple script. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431273 Share on other sites More sharing options...
Monkuar Posted May 20, 2013 Author Share Posted May 20, 2013 This could be done using JavaScript; You could assign a unique ID to all the slots in the inventory, and then load the items using a JS file that would fetch the data from a PHP file with access to the database. On a side note, I don't think you'd need to store the exact position of each item in the database. If you'd need to know in which slot an item is located, you could find out with a simple script. would each slot need to be a row in the database then? im a bit confused, sorry Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431274 Share on other sites More sharing options...
BorysSokolov Posted May 20, 2013 Share Posted May 20, 2013 It depends. How will the inventory be used? Will the items switch slots often? If so, then I think it'd be better to create a table for the items only, with each item being a different row. The positions of the items shouldn't be stored directly in the database, though. You could determine which slot an item is located in on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431275 Share on other sites More sharing options...
Monkuar Posted May 20, 2013 Author Share Posted May 20, 2013 It depends. How will the inventory be used? Will the items switch slots often? If so, then I think it'd be better to create a table for the items only, with each item being a different row. The positions of the items shouldn't be stored directly in the database, though. You could determine which slot an item is located in on the fly. Well the items will be in users_user_items or whatever, if a user has Long Sword, it will be unique to him, and have it's own id to that player. I also will have a main items table to keep track of items/etc I'm still completely lost... So let's say user a finds a Long sword, how would i sychronise that unique item name to a position in his inventory? I just don't get it :/ Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431277 Share on other sites More sharing options...
BorysSokolov Posted May 20, 2013 Share Posted May 20, 2013 You'd need to use Javascript, it's not possible with PHP alone, unless you're willing to tolerate the page refreshing anytime an item in the inventory is changed. If you don't know any Javascript, then I suggest you look into it before continuing with the project. With the javascript, you would be able to select each of the slots in the inventory by their ID (which you would assign in HTML), and input the loaded item into the given space. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431280 Share on other sites More sharing options...
mac_gyver Posted May 21, 2013 Share Posted May 21, 2013 what significance is there to what box any item is located in? isn't it enough that you have an item in your inventory? Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431281 Share on other sites More sharing options...
Monkuar Posted May 21, 2013 Author Share Posted May 21, 2013 what significance is there to what box any item is located in? isn't it enough that you have an item in your inventory? Because if a user moves it , it needs to remember the location xD Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431284 Share on other sites More sharing options...
teynon Posted May 21, 2013 Share Posted May 21, 2013 Your inventory box is a grid. Label your grid the same way you would any grid and store that grid id in MySQL. Read Left to right, top to bottom. For example: 1 2 3 4 5 6 7 8 9 10 11 12 If you plan on expanding width of the inventory, use a col and row naming convention similar to excel or a chess board. 1 | 2 1 1,1 | 2, 1 2 1,2 | 2, 2 Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431290 Share on other sites More sharing options...
Monkuar Posted May 21, 2013 Author Share Posted May 21, 2013 (edited) Your inventory box is a grid. Label your grid the same way you would any grid and store that grid id in MySQL. Read Left to right, top to bottom. For example: 1 2 3 4 5 6 7 8 9 10 11 12 If you plan on expanding width of the inventory, use a col and row naming convention similar to excel or a chess board. 1 | 2 1 1,1 | 2, 1 2 1,2 | 2, 2 Okay, so for each user's item that the person owns, it has to have a row/column name "gridnumber" or something. (The position). So let's say: Long sword is 1 Iron Helmet is 7 Then I need to update these if a user drags them or presses a button. I can do ajax/js later. But that would right? Now I have Long Sword 1 and Iron Helmet 7. how would I show these in that grid via output? I'm getting closer to this ty all but please pitch in any more help ty Edited May 21, 2013 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431291 Share on other sites More sharing options...
Q695 Posted May 21, 2013 Share Posted May 21, 2013 He can do it in PHP on another screen, like move.php. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431297 Share on other sites More sharing options...
teynon Posted May 21, 2013 Share Posted May 21, 2013 I'm going to sleep and typing this from my phone, but I thought of one possible alternative here. Instead of tracking an item, track a slot. So in the database, a user has 20 slots. Each slot can have an itemid or null. This means that as your collection of different types of items grow, your database will not grow exponentially. You would have one record per actual item. Your main database would grow predictably depending on your user count and selecting it might be a bit easier. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431299 Share on other sites More sharing options...
Monkuar Posted May 21, 2013 Author Share Posted May 21, 2013 He can do it in PHP on another screen, like move.php. Yes move.php would be the update function part.... I'm looking for an output. Sword is in 1 Iron Helmet is in 7. I have a Grid with CSS/html displayed, how to show the items in the correct box? :PPPP (I get data from mysql, but how to show) Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431303 Share on other sites More sharing options...
ignace Posted May 21, 2013 Share Posted May 21, 2013 users (user_id, ..) inventory (user_id, item_id, loc_row, loc_col) items (item_id, width, height)Your item should have a width/height expressed in the number of rows/cols it consumes. Then knowing your inventory is n1 x n2 you can simply calculate whether the selected location fits inside your grid. To display the grid you would first have to create the grid, and float the item over it at the specified position of loc_row. Using js you can make it snap to the grid lines. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431306 Share on other sites More sharing options...
mac_gyver Posted May 21, 2013 Share Posted May 21, 2013 Because if a user moves it , it needs to remember the location xD that's not an answer to - what significance is there to what box any item is located in? that's a statement of what you are doing. why not just display the items in any person's inventory, in the boxes, in alphabetical order or in the order they were acquired in, starting at the top-left box? you are having difficulty with storing the location, just think how much code it will take to allow someone to change the location and prevent overwriting a location already in use? Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431342 Share on other sites More sharing options...
Muddy_Funster Posted May 21, 2013 Share Posted May 21, 2013 that's not an answer to - what significance is there to what box any item is located in? that's a statement of what you are doing. why not just display the items in any person's inventory, in the boxes, in alphabetical order or in the order they were acquired in, starting at the top-left box? you are having difficulty with storing the location, just think how much code it will take to allow someone to change the location and prevent overwriting a location already in use? I am getting the impression this isn't an inventory as much as it is an equipped items display...where the location of the item is relevant, if not he may just want to allow the end user the ability to organize the items in their inventory (with persistence) to their personal preference, not the order that they are picked up in (cash sale items in the bottom row, weapons in the first and clothing in the second for example). Or perhaps the intent is to include hotkeys to activate items in certain slots. That's just off the top of my head, I haven't even thought about this in any great thought. As for displaying the items, you would loop through the array of data retrieved from the data base as you are rendering the grid and apply the (I assume) image to the relevant cell as it is being drawn. Quote Link to comment https://forums.phpfreaks.com/topic/278223-inventory-management-storing-items-in-boxes/#findComment-1431347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.