mike1313 Posted April 2, 2007 Share Posted April 2, 2007 Okay so for my MMORPG, there are player-owned guilds that have an armory where they can store their weps/armor but when it shows what the armory holds if it is more than one of the same item they stack instead of showing Sword Sword I want it to display 2 Sword. How can I do this? while ($armo = mysql_fetch_array($arm)) { if($armo[type] == "Weapon"){ $t = "W";} if($armo[type] == "Armor"){ $t = "A";} echo "<tr><td><li type=square></td><td>[<b>$t</b>]</td><td>$armo[item]</td><td> [<b>E</b>]: $armo[effect]</td></tr>"; } Quote Link to comment Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 Need more code man, what is the query you are running? Does it return a quantity if you know the quantity you want to do something like this: while ($armo = mysql_fetch_array($arm)) { $i=0; while ($armo['quantity'] < $i) { if($armo[type] == "Weapon"){ $t = "W";} if($armo[type] == "Armor"){ $t = "A";} echo "<tr><td><li type=square></td><td>[<b>$t</b>]</td><td>$armo[item]</td><td> [<b>E</b>]: $armo[effect]</td></tr>"; $i++; } } Note that will only work if quantity is actually in the DB, post more code if you want a more accurate response. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted April 2, 2007 Author Share Posted April 2, 2007 $arm = mysql_query("SELECT * FROM order_arm WHERE `order`='$order[id]' ORDER by effect asc"); while ($armo = mysql_fetch_array($arm)) { if($armo[type] == "Weapon"){ $t = "W";} if($armo[type] == "Armor"){ $t = "A";} echo "<tr><td><li type=square></td><td>[<b>$t</b>]</td><td>$armo[item]</td><td> [<b>E</b>]: $armo[effect]</td></tr>"; } Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 the only way this would work is if you didnt put the display code - echo - in the loop. ex $num = 0; while(...){ if(this is true) $num++; } echo $num; i may be wrong, i dont fully understand whats going on though Quote Link to comment Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 Can you post your DB structure dude. It is hard to diagnose the problem when you are not giving us enough information. Its like me telling you to find out google's search engine secret, impossible without some type of access to the code. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted April 2, 2007 Author Share Posted April 2, 2007 If you want the fields they are as such for the db table id - auto_increment order (int) item (varchar) type(varchar) effect(int) equipped(varchar) req_lvl (int) Each time someone puts something into the armory it makes a new row. Quote Link to comment Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 And are you sure there are 2 swords in the armory to print out? It seems to me like that should work like you expect it to. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted April 2, 2007 Author Share Posted April 2, 2007 No it outputs Sword Sword as many times as there is item='Sword' so with that echo and while loop and there where 3 swords it would display Sword Sword Sword Quote Link to comment Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 So you only want it to echo sword once, that is simple my friend. $arm = mysql_query("SELECT * FROM order_arm WHERE `order`='$order[id]' GROUP BY type ORDER by effect asc"); while ($armo = mysql_fetch_array($arm)) { if($armo[type] == "Weapon"){ $t = "W";} if($armo[type] == "Armor"){ $t = "A";} echo "<tr><td><li type=square></td><td>[<b>$t</b>]</td><td>$armo[item]</td><td> [<b>E</b>]: $armo[effect]</td></tr>"; } Try that out. Added a GROUP BY statement. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted April 2, 2007 Author Share Posted April 2, 2007 Okay works great, 1 more thing, how would I like I orginally wanted so if I had 3 swords how would I make it put a 3 beside the name? Quote Link to comment Share on other sites More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 $arm = mysql_query("SELECT * FROM order_arm WHERE `order`='$order[id]' ORDER by effect asc"); while ($armo = mysql_fetch_array($arm)) { if (in_array($armo['item'], $armArr)) { $armArr[$armo['item']]['quantity']++; }else { $armArr[$armo['item']] = $armo; $armArr[$armo['item']]['quantity'] = 1; } } foreach ($armArr as $armo) { if($armo[type] == "Weapon"){ $t = "W";} if($armo[type] == "Armor"){ $t = "A";} echo "<tr><td><li type=square></td><td>".$armo['quantity']."[<b>$t</b>]</td><td>$armo[item]</td><td> [<b>E</b>]: $armo[effect]</td></tr>"; } something along those lines. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted December 30, 2007 Author Share Posted December 30, 2007 I've tried using that over to count the number but it's not working it's just running the else { $armArr[$armo['item']] = $armo; $armArr[$armo['item']]['quantity'] = 1; } the code again $arm = mysql_query("SELECT * FROM order_arm WHERE `order`='$order[id]' ORDER by effect asc"); while ($armo = mysql_fetch_array($arm)) { if (in_array($armo['item'], $armArr)) { $armArr[$armo['item']]['quantity']++; }else { $armArr[$armo['item']] = $armo; $armArr[$armo['item']]['quantity'] = 1; } } foreach ($armArr as $armo) { if($armo[type] == "Weapon"){ $t = "W";} if($armo[type] == "Armor"){ $t = "A";} echo "<tr><td><li type=square></td><td>".$armo['quantity']."[<b>$t</b>]</td><td>$armo[item]</td><td> [<b>E</b>]: $armo[effect]</td></tr>"; } I've tested it using 2 items of the same thing and it only displays 1 instead of 2. Quote Link to comment 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.