supanoob Posted September 1, 2007 Share Posted September 1, 2007 Ok, so i have a database with lots of items in it these items vary from things people will be able to "equip" to things that could "eat". Now what i want to do is make it so the items will be echoed only once if they have more than 0 of them. for example they have more than 0 Swords it would echo the image once but underneath it would have the actual ammount they have. Now since i am going to have 100's maybe 1000's of items in game it would be a real pain to write out a search code for each item and then have an if statement to see if it is > than 0. I was wondering if anyone could advise on a quicker more efficient way of doing this. If so could you please tell me thanks in advance, Supanoob. Quote Link to comment https://forums.phpfreaks.com/topic/67565-solved-quick-question/ Share on other sites More sharing options...
pocobueno1388 Posted September 1, 2007 Share Posted September 1, 2007 Just do a query that will group the items together by name. <?php $query = mysql_query("SELECT count(name) as amount, image FROM items WHERE ownerID='$ownerID' GROUP BY name")or die(mysql_error()); //display them while ($row = mysql_fetch_assoc($query)){ echo '<img src="'.$row['image'].'"><br>'; echo '<b>Amount:</b>:'.$row['amount'].'<p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67565-solved-quick-question/#findComment-339381 Share on other sites More sharing options...
supanoob Posted September 1, 2007 Author Share Posted September 1, 2007 but the items will have different names, i know how to count them, its just i dont wanna have to do a different query for each name. Quote Link to comment https://forums.phpfreaks.com/topic/67565-solved-quick-question/#findComment-339425 Share on other sites More sharing options...
pocobueno1388 Posted September 1, 2007 Share Posted September 1, 2007 It's okay that the items will have different names, that one query will take care of ALL of them. Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/67565-solved-quick-question/#findComment-339430 Share on other sites More sharing options...
supanoob Posted September 1, 2007 Author Share Posted September 1, 2007 nope i will now and let you know if it works Quote Link to comment https://forums.phpfreaks.com/topic/67565-solved-quick-question/#findComment-339447 Share on other sites More sharing options...
supanoob Posted September 1, 2007 Author Share Posted September 1, 2007 Worked Fine thanks Quote Link to comment https://forums.phpfreaks.com/topic/67565-solved-quick-question/#findComment-339452 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.