I'm working on a game that allows players to store items in a MySQL database. I've got a table that stores every player's items. It's slot based, with each item having a unique value. So the table would have something like: id, itemvalue, slot, playerID.
I'm trying to figure out a way in PHP to allow the player to withdraw or deposit an item in a specific slot.
I need help updating entries after an action (withdraw or deposit) has taken place. For example: Say a player can have 10 slots for themselves. If the player withdraws an item from slot 4, how do I loop through their items from slots 5 to 10 and update the values to be -1 for their slot.
Of course, I'm getting the information from the table, let's call it "ItemTable" by using:
$sql = mysql_query("SELECT * FROM ItemTable WHERE playerID ='$_playerID' ORDER BY id ASC LIMIT 10");
mysql_queryinterface. It's awful and is being removed in future versions of PHP. A modern replacement like PDO is not hard to learn. A guide like PHP The Right Way can help explain best practices. Always be absolutely sure your user parameters are properly escaped or you will have severe SQL injection bugs.