jBooker Posted November 13, 2008 Share Posted November 13, 2008 Hmm.. I'm at a lose of words.. I got this game, private server, Fly For Fun and I've been making a 'character CP' with many interesting options for in-game effects to said character. I've gotten the idea to make a web inventory that mimics the characters in-game inventory by displaying the item icon in the correct inventory slot/square. I have successfully gotten the in-game item icon converted to .bmp and gotten them to display properly but I cant figure out how to code it so that the item icon will be shown in the correct inventory slot. You still with me? .. OK.. Now, the Table 'inventory' is where it tells the game server what slot the items are in with the column 'inventoryslot'. My problems source is here, when there is no item in a slot then there is no row entry for that slot. The inventory has 42 slots, 0 through 41, seven rows of 32x32 squares and six columns. Here's a table with the 'inventoryslot' numbers to give you a visual of the inventory: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 So what I cant figure out is how to show 42 32x32 squares that are empty when there is no mysql row in table 'inventory' with the slot number and when there is it will show the item icon in the square. So far the closest I've gotten is with this: echo "<table style='float: right; margin-right: 5px;'>"; echo "<tr>"; $inventory = mysql_query("SELECT * FROM inventory WHERE charid = '$id' AND backpack_number = '-1' AND inventoryslot >= '0' AND inventoryslot <= '5' ORDER BY inventoryslot ASC") or die(mysql_error()); $checkinv = mysql_num_rows($inventory); $listitms = $checkinv; while ($get = mysql_fetch_assoc($inventory)) { $listitms--; $itemid = $get['itemid']; $item = mysql_query("SELECT * FROM data_item WHERE id = '$itemid'") or die(mysql_error()); $getimage = mysql_fetch_assoc($item); $itemimg = str_replace('"','',$getimage['iconPath']); if ($get['inventoryslot'] == '0') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '1') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '2') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '3') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '4') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '5') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE { echo "<td width='32' height='32'> </td>"; } } echo "</tr>"; echo "</table>"; That just shows the items in the first inventory row. The problem is that when there is no item in a slot (aka; no mysql row with inventoryslot == 0/1/2/3/4/5) then it does not show an empty 32x32 square, it just skips it. I know its possible I just don't have enough PHP knowledge to figure it out. =/ Hope someone can help. Link to comment https://forums.phpfreaks.com/topic/132579-trying-to-display-an-mmorpg-characters-inventory-using-mysql-data/ Share on other sites More sharing options...
bobbinsbro Posted November 13, 2008 Share Posted November 13, 2008 try this: <?php echo "<table style='float: right; margin-right: 5px;'>"; echo "<tr>"; $inventory = mysql_query("SELECT * FROM inventory WHERE charid = '$id' AND backpack_number = '-1' AND inventoryslot >= '0' AND inventoryslot <= '5' ORDER BY inventoryslot ASC") or die(mysql_error()); $checkinv = mysql_num_rows($inventory); $listitms = $checkinv; $itemCount = 0; //used to create the empty items while ($get = mysql_fetch_assoc($inventory)) { while ($get['inventoryslot'] - $itemCount > 0){ echo "<td width='32' height='32'><img src='items/empty.bmp'></td>"; ++$itemCount; } $listitms--; $itemid = $get['itemid']; $item = mysql_query("SELECT * FROM data_item WHERE id = '$itemid'") or die(mysql_error()); $getimage = mysql_fetch_assoc($item); $itemimg = str_replace('"','',$getimage['iconPath']); if ($get['inventoryslot'] == '0') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '1') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '2') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '3') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '4') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE if ($get['inventoryslot'] == '5') { echo "<td width='32' height='32'><img src='items/$itemimg.bmp'></td>"; } ELSE { echo "<td width='32' height='32'> </td>"; } ++$itemCount; } echo "</tr>"; echo "</table>"; ?> what i did was add: * a variable $itemCount on line 7 to keep track of the item that should be now. initialized to 0. * a loop on lines 10-13 that will print the empty slot image in a new cell as long as the $itemCount hasn't caught up with the current item location (stored in $get['inventoryslot']). i assumed the empty image is called empty.bmp. change it if i'm wrong (line 11). * increment $itemCount at the end of the main while loop (your original one) to keep track of the expected item slot. i'm not sure why you have lines 6, 14 (in the version i posted), as you don't use that variable anywhere. also, i read somewhere that switch() statements execute faster than if...else if statements in php. i haven't tested this though. Link to comment https://forums.phpfreaks.com/topic/132579-trying-to-display-an-mmorpg-characters-inventory-using-mysql-data/#findComment-689527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.