PHP - Inventory Management Storage
Before reading: I already have a system in place for inventory management. I use it with a rpg_items database with a field called 'item_slot', etc and it works wonderfully.
My issue is. I think it would be intuitive if I were to store a basic 20 slot 0 iteration in a field under the users table for each character. So I can just check against that, instead of querying the whole rpg_user_items table, (which will have thousands, hundreds of thousands of users items) to just check if a user's inventory is full, that is not intuitive. I'd rather just check if a field name has no open 0's instead with php. (This ofcourse will be updated dynamically upon a user moving their items to different slots). Let's say I have this array, and it's stored in a field called userinventory in the users table: 0,0,0,0,0 0,0,0,0,0 0,0,0,0,0 0,0,0,0,0This is pretty easy to read. there is 20 slots, 5 on reach row. That's 20 inventory slots a user has access to. This is supposed to represent something like this: I can store this in the MYSQL field as 'userinventory'. Now, how do I go about dynamically each specific 0 (ZERO) in this Block? I'm going to call this a block. I will need to label it accordingly. Paint time. Here u go How do I use PHP to dynamically update a block like this based upon user input? (A 1, A 2, A3, B2, B1, etc) To check if a user's inventory is full would be easy. I can just explode them by ',' and use count to see if it's greater than 20. My problem is about updating each individual block to represent a users inventory. So, if there is a 1 there, an item would be there. That's all I'm trying to do. I could ofcourse, create what 20 (5x4) if functions to place them at each individual block, but that wouldn't be intuitive and be extremely confusing. Edited by Monkuar, 23 January 2015 - 09:08 PM. Similar TutorialsI'm going to MAKE this task very simple for you. I am just not that experienced with php yet to conquer this specific task. Let me get you started with some examples of how easy the client side of this is. Copy and paste this and run it as index.php on your dev server: <script src="http://code.interactjs.io/interact-1.2.2.min.js"></script> <script> function qs(expr){return document.querySelector(expr)} </script> <style> .fadeIn{animation-name:fadeIn;-webkit-animation-name:fadeIn;animation-duration:.7s;-webkit-animation-duration:.7s;animation-timing-function:ease-in-out;-webkit-animation-timing-function:ease-in-out;visibility:visible!important}@keyframes fadeIn{0%{transform:scale(0);opacity:0}60%{transform:scale(1.1)}100%{transform:scale(1);opacity:1}}@-webkit-keyframes fadeIn{0%{-webkit-transform:scale(0);opacity:0}60%{-webkit-transform:scale(1.1)}100%{-webkit-transform:scale(1);opacity:1}} .InventoryTest{ border:1px solid #D3D3D3;border-bottom:0;width:24px;height:24px;float:left;padding:3px;border-right:0; } .itemdrag{position:relative;z-index:1} .InventoryTest:nth-child(9n+9){ border-right:1px solid #D3D3D3 } .InventoryTest:nth-last-child(-n+9){ border-bottom:1px solid #D3D3D3; } .itemdrag{position:relative;z-index:1} </style> <?php error_reporting(E_ERROR); //Display 63 boxes (Fits with the css nth-child tags to look pretty! lol) for($i = 1; $i < 64; $i++){ if ($i == 1){ // Slot positions 1 Dimensions: 3x3 (lengthXwidth) $item1 = '<div class="itemdrag" item_id='.$i.' data-cslot='.$i.'><img src=http://i.imgur.com/3azYLNf.png></div>'; }elseif($i==4){ // Slot position 2 Dimensions 2x1 lengthXwidth) $item1 = '<div class="itemdrag" item_id='.$i.' data-cslot='.$i.'><img src=http://i.imgur.com/l3y0W7d.png></div>'; }else{$item1 = '';} $inventoryboxes .= '<div class="InventoryTest" data-slot='.$i.'>'.$item1.'</div>'; } ?> <div style="width:300px"> <?php echo $inventoryboxes ?> </div> <script> // target elements with the "draggable" class interact('.itemdrag') .draggable({ // enable inertial throwing inertia: true, onstart: function (event) { }, // call this function on every dragmove event onmove: function (event) { var target = event.target, // keep the dragged position in the data-x/data-y attributes x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx, y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; // translate the element target.style.position = "relative"; target.style.zIndex="2500"; target.style.webkitTransform = target.style.transform ='translate(' + x + 'px, ' + y + 'px)'; // update the posiion attributes target.setAttribute('data-x', x); target.setAttribute('data-y', y); }, // call this function on every dragend event onend: function (event) { var target = event.target; target.removeAttribute("style"); target.removeAttribute("data-x"); target.removeAttribute("data-y"); } }); interact('.InventoryTest').dropzone({ // only accept elements matching this CSS selector accept: '.itemdrag', // Require a 75% element overlap for a drop to be possible overlap: 0.40, // listen for drop related events: ondropactivate: function (event) { var draggableid = event.relatedTarget; // add active dropzone feedback // Is this and item that can be equipped? if (event.relatedTarget.getAttribute('item-type') != "Misc"){ //qs('#shadow'+draggableid.getAttribute('item-type')+'').style.display='none'; } event.target.classList.add('drop-ACCEPT'); }, ondragenter: function (event) { var draggableElement = event.relatedTarget, dropzoneElement = event.target; // feedback the possibility of a drop dropzoneElement.classList.add('drop-target'); draggableElement.classList.add('can-drop'); //draggableElement.textContent = 'Dragged in'; }, ondragleave: function (event) { // remove the drop feedback style event.target.classList.remove('drop-target'); event.relatedTarget.classList.remove('can-drop'); //event.relatedTarget.textContent = 'Dragged out'; }, ondrop: function (event) { var dragid = event.relatedTarget; if (event.target.hasChildNodes()) { //console.log(event.target.childNodes[1]); return; } var slotp = event.target.getAttribute("data-slot"); var slotp2 = event.relatedTarget.getAttribute("data-cslot"); var shadowid = qs('#shadow'+dragid.getAttribute('item-type')+''); var item_id = event.relatedTarget.getAttribute("item_id"); // <-- The one being dragged //We need to show the shadow gear again. (shadowid) ? shadowid.style.display='inline-block': ''; qs('[data-slot="'+slotp2+'"]').innerHTML=''; qs('[data-slot="'+slotp+'"]').appendChild(event.relatedTarget); event.target.childNodes[0].setAttribute("data-cslot", slotp); //We do our ajax functions here, just log the information for now: console.log(" item_id="+item_id+"&slot_go="+slotp+" "); event.relatedTarget.className += ' fadeIn'; //console.log(event.relatedTarget); //console.log(event.target); //event.relatedTarget.textContent = 'Dropped'; }, ondropdeactivate: function (event) { // remove active dropzone feedback event.target.classList.remove('drop-ACCEPT'); event.target.classList.remove('drop-target'); } }); </script>Now, go there and drag and move the belt around in the inventory. They should update accordingly. Example: Press F12 and check your console. You should see upon each item being moved, it's logging their slot it was moved. What I need? I need this where items CANNOT overlap each other in the inventory. The items need to be piped from mysql and positioned to the appropriate position in the inventory. You need to be experienced in Javascript and PHP for this. InteractJS because if you check the example above, the armor is being dragged, but you cannot drop it on anything because interactjs doesn't know it's that big. If you look at Diablo 2's inventory system, and Path of Exile's or Diablo 3's, you can get an idea of what I'm looking for. Let me know if you're interested in this and what price. There is a field in my rpg_user_items table called slot_position and slot_size. slot_size represents the widthxheight of the item. (in this example and code above, it's 3x3 (armor) and 2x1 (belt). Edited by Monkuar, 24 January 2015 - 08:39 PM. I have an sql database that is updated via a PHP website. It is to track inventory. I can read from the DB and display the information and photos on the page. What I need is to be able to click on an item number of any listing on the page and pull up more info (ie photos) on another page of that listing. Kind of like a car dealership. You search for a vehicle, and several vehicles are displayed. You click on the vehicle you want and are sent to a page with more information on the selected vehicle. If any of this doesnt make sense, let me know.
Hello everyone! i'm just having a little bit of a play around making a browser-based text RPG with PHP and mySQL. But when it comes to creating a system where a player can view their inventory, and for that matter -have- items. i just don't know where to begin. Would i make a seperate database for inventories and have each column in the database be a different inventory slot and then have the value in that field be in reference to an item? like 1 = potion, 2= ether, etc? with a large amount of items and inventory space for each player i don't want to get started down a long road on the wrong path. To reiterate, I'm not asking for the code specifically i'm just asking what way I would go about it. What would be the simplest, least headachey method of such a system? Hi, What is a good way to store passwords using php and postgresql and what columns/column types do I need to do so? I've got a table 'users' I've tried to find a straight forward answer but am confused by 'salting' etc. Thanks I'm busy with a small storage system for my site, but i encounter some problems with it. I have successfully managed to get all products from the order, and traced on what spots those product are in the warehouse. It looks like this atm http://img37.imageshack.us/img37/7302/tableordereng.jpg this is the code i have atm (sorry i program in dutch, i hope its abit understandable) Code: [Select] <?php $query = "select * from `orderregel` WHERE `ordernr`='".$ordernr."'"; $row = mysql_fetch_array( $query ); echo "<table border=1 width=680 bgcolor=#FFFFFF> <tr> <th width= 100>artikelnummer</th> <th width= 100>productnaam</th> <th width= 40>Plaats</th> <th width= 40>aantal in magazijn</th> <th width= 40>aantal nodig</th> </tr> </table>"; foreach ( self::find_by_sql($query) as $user) { $query2 = "select * from magazijn WHERE artikelnr = ".$user->artikelnr.""; $row = mysql_fetch_array( $query ); foreach ( self::find_by_sql($query2) as $magazijn) { echo "<table class= order_overzicht border= 0 width= 680>"; echo "<tr> <td width= 100>".$magazijn->artikelnr."</td> <td width= 100>".$magazijn->productnaam."</td> <td width= 40>".$magazijn->magazijn_plaats."</td> <td width= 40>".$magazijn->aantal."</td> <td width= 40>".$user->aantal."</td> </tr> </table>"; } } ?> The problem i have now is, that i want it to do the following. for example someone orders 430 packages of Haribo Kers Cola (see imageshack upload). I first want it to empty spot 16 in the wherehouse. Only when spot 16 is empty, i want it to go to the next spot (19) wich contains the same product. the end result would be something like this: http://img690.imageshack.us/img690/6246/tableorderneweng.jpg i hope you guys can help me out on this one, becouse i have no clue how i can resolve this problem thanks in advance (Sorry btw for my bad english ) My users table on my forum is what gets checked everytime a user refreshes to authentic them.
When killing a monster, I want users to be able to grab items and it will insert them into their inventory. I have this part done already. But I want them to have a plethora of loot available that drops from a mob, and once they click the specific item it will then be inserted into their inventory (server database).
I'm storing the Temporary Item Data in a PHP session variable. Once they kill a monster, the Tempory Item Data variable get's filled with the specific loot and then the user will have the option to choose what items they want to go into their inventory.
My problem is, if they open the game in a new browser they will get a new session id. Since I'm authenticating them through my users table, can I just make a new column called session_id and just use php's session_id() before every session start so no matter which browser they're on they will have the same session right?
You might think, well why dont you just store the temporary item data in a mysql field or rows instead? I want to try to minimize mysql usage as much as possible, as players will be CLICKING a lot to kill mobs, it is most likely very mysql demanding as well and I want to be intuitive about it. I just want to use temporary session data for the loot. Then once the user clicks an item they want, it is EXTRACTED from their tempory item data variable, then I will use MYSQL to insert those items into their inventory.
Is this a fair and intuitive way to do temporary data for item loot? For example, in action RPG's like Path of Exile you kill a group of mobs and you see a shit ton of loot on the floor. (I imagine that loot is just temporary waiting for someone to pick it up right?) Once you do pick it up, mysql is then called to save it right? That's the same logic I have with my web based game. Is using a session variable to store that temporay loot.
Is this an intuitive way to do this, or are there other ways?
Edited by Monkuar, 24 November 2014 - 01:24 AM. Just curious, how would you go about rendering and storing this in a database. For example a simple small maze.
With each keypress, the user is moved up,down,left,right like 1 inch. (1 block). Which is easy to do with jquery, etc. But how would go about storing the data in a databse (can update the position per update or using websockets), but essentially so maphacks are impossible and everything is saved/read from the server.
Would the storage data be something like [0,0,0,1,0,0,1,1,1,1,0,1] I imagine or what?
Edited by Monkuar, 01 December 2014 - 09:32 PM. I am trying to do age validation for a beverage site, and losing my mind. First time trying local storage (to persist across browser sessions) and I assume I have something screwed up. Anyone able to help me figure out how to make this work? <?php if( isset( $_POST['yes'] ) ) { localStorage.setItem('age_verification', 'true'); if( isset( $_GET['url'] ) ) { die( header('Location: ' . $_GET['url'] ) ); } else { die( header('Location: index.php') ); } } elseif( isset( $_POST['no'] ) ) { localStorage.setItem('age_verification', 'false'); } var age_verification = localStorage.getItem('age_verification'); //new if (age_verification = "false" || age_verification = "null") die( header('Location: http://www.bing.com') ); ?> Above is the code for the file checkagenew.php which I call from other pages using the below: <?php if (localStorage.age_verification) { localStorage.setItem('age_verification', 'null'); } var age_verification = localStorage.getItem('age_verification'); if (age_verification = "false" || age_verification = "null") die( header("Location: checkagenew.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]") ); ?> Obviously there is a form included in the top part (not shown) that has a submit for yes/no which triggers the $_POST validation... I did not include that for brevity. Hey guys, I'm trying to build a simple 'blogging engine' as a fun side project. At the moment i'm mainly having trouble with 2 things - 1. What is the best way that the administrator can input the data (with linebreaks, etc) and then have it stored in the database with this formatting so that when it is called from the database, it shows up the same on the page? 2. How do i go about selecting only certain posts from the database? I have tried doing a /post.php?id=12 and then an SQL statement "WHERE post_id=" . $id (in the correct formatting, of course) but this didnt seem to work. Any help would be appreciated. -CynePhoba after authenticating username and password,i have a parameter like: $_SESSION['logged']=1 should i be storing this as a cookie?..if yes, then can anyone modify cookie, to have this parameter as "1", and gain access? Hi, My php application works abnormal. The used code to mange session is: Code: [Select] include_once "classesFiles"; session_start (); // check for the first visit if (!isset ($_SESSION ['anObject'])) $_SESSION ['anObject'] = new Object (); $username = "xxx"; $password = "yyy"; if (isset ($_POST ['username']) && isset ($_POST ['password']) && $_POST ['username'] == $username && $_POST ['password'] == $password) $_SESSION ['anObject'] -> setRole (Role::ADMIN); if (InputChecker::getPageAction ($_GET ['p']) == PageAction::LOGOUT) $_SESSION ['anObject'] -> setRole (Role::VISITOR); ... I tested the code as follow: 1- go to the site 2- log in 3- make a new tab in the same browser 4- go to the site from the new tab (I am already logged in) 5- log out from the new tab 6- go to the first tab 7- refresh the tab. I am still logged in (I find this behavior abnormal) The second test: 1- go to the site 2- log in 3- make a new tab in the same browser 4- go to the site from the new tab (I am already logged in) 5- go to the first tab 6- log out 7- go to the second tab 8- refresh the tab. I am logged out (I find this normal) The order of tabs from which I log out is important. Does anyone have an idea why the first test dose not work normal? Thanks, Hi, I am very new to PHP, I have managed to create a basic database with a table of users, and a form for logging in. Is there a way to create an 'area' where the users that are logged in can view, upload and download files. For example, a file storage area just like dropbox? If so, can anyone share some basic code or links to tutorials to achieve this please. Afterwards, I would then like to set permissions for each of the users to only access certain folders within that 'storage area'. I realise there are many websites like dropbox and box.net, but I would like to code my own version. Thanks in advance Hi
I am new to php i want to develop a code where i can upload images from backend and also able to delete selected images
please provide me help for it
I have a general knowledge of PHP. I was wondering if anybody knew of a script that when a user logs in, they have their own unique page setup, but it is the same page. Basically so a client could log in and see the information about their purchase, or website construction etc. Any scripts to build off of? Thanks Hello,
I'm looking for server management software, preferably free or low cost. I did some googling but could not come up with a good solution for what I need. I manage a small data center and currently keep all server information (IPs, Rack ID, Client ID, etc) in an excel sheet. Does anyone know of something that I can manage the server information more efficiently?
Thanks
Hi all, I'm starting an new project where I'm making an Incident Management System and right from the start I don't know what to do. Could anyone get me on my way. I need to make a script where if I open a new incident the new page opens and automatically gets a new Incident number. This number is offcourse 1 number higher every time you make a incident. I thought about make a column with autoincremetn and then query the highest number. Problem with that is when you open a page at multiple computers at the same time they get the same number. Does anyone have an idea? Ryflex Okay, well for a site i want to make a user managment system. but i have no idea how to. ive already got the part where you type the user that you want to manage. Code: [Select] <?php /* Copyright (C) 2009 Murad <Murawd> Josh L. <Josho192837> This program is free softwa you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ // Must rewrite ?> <fieldset> <legend> Manage User </legend> <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> <tr class="navtitle" style="height:25px"> <th style="width:auto">Manage A User</th> </tr> <tr> <td align="center" class="tdbox"> Search for the profile name you wish to manage. </td> </tr> <tr> <td align="center"> <form method="post" action=''> <input type="text" name="name" /> <input type="submit" name="search" value="Search" /> </form> </td> </tr> <tr style="height:25px"> <td class="tdbox"> <span style="float:left"> <a href="?cype=admin">Back To Administration Control Panel</a> </span> </td> </tr> </table> </fieldset> But thats just to find the user you want to edit, i want to make it so i can edit there name, how much money and such they have. instead of going into the db. so if you could help or if you need more info just ask. i dont really no much to put up here. The idea: an authorized web user (novice) uploads an Excel spreadsheet via FTP to a website. The spreadsheet contains 9 rows and 5 columns, which will look something like this: 12345 | sky | blue | sunny | happy | ------------------------------------------- 54321 | water | green | cold | sad | ------------------------------------------- etc ... The script I'm looking for would show the first 3 of the 9 rows at the same time and rotate to the next 3 on refresh and so on. The output of the script would look something like this: <div><p><a href="http://www.xyz.com/12345.html>;<img src="http://www.xyz.com/12345.jpg" /></a><br /> <strong>sky</strong><br />blue<br />sunny<br />happy</p><br /> <p><a href="http://www.xyz.com/12345.html">Details</a></p></div><br /> <div><p><a href="http://www.xyz.com/54321.html>;<img src="http://www.xyz.com/54321.jpg" /></a><br /> <strong>water</strong><br />green<br />cold<br />sad</p><br /> <p><a href="http://www.xyz.com/54321.html">Details</a></p></div> etc... the script structure would always be the same but the values of each div would change based on the row values of the spreadsheet. Can this be done? I was wondering if there's any common method for user management. I'm not talking about basic stuff like DB management stuff I'm talking about registering new users with captcha, validating email addresses, password resets, etc. I can work all this stuff out by hand but it seems rather large and very repetitious so I was wondering if there's guides out there to develop this or a common script? |