I started similar thread but as the problem is more difficult, I would like to start from scratch.
Imagine there are 10 inventory slots (in DB they are columns in the user’s row). When an users picks an item up, it should be placed into the first empty column (it gets updated). But how to do the looping through the columns (except for IF EXISTS) in the query if I want to have still flexible design?
It cannot be solved well by having the items in rows as the order of items matters (each item belongs to particular slot). If the users has 1nd and 3rd slot full, next picked item should go into the 2nd.
Hope its more clear now, thanks!
I started similar thread but as the problem is more difficult, I would like
Share
Why not just have another table for the inventory items? So you’d have an inventory table and inventory_item table, like this:
So now, you could have a row in inventory, and then you could insert the rows into inventory_item as you get the values. So if you have 3 values, you would just insert the 3 rows into inventory_item. As for what “slot” they go in, the sequence_num field would tell you that.
EDIT
To query for existing inventory_items to find out the next available slot number, you could do something like:
If no inventory_items exist, this would return 1. If existing items are present, it will give you the next “slot number” to use (I call it sequence_number, but same thing).