Jump to content

[SOLVED] Quick Question


supanoob

Recommended Posts

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 :D

 

thanks in advance, Supanoob.

Link to comment
https://forums.phpfreaks.com/topic/67565-solved-quick-question/
Share on other sites

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>';
}

?>

Link to comment
https://forums.phpfreaks.com/topic/67565-solved-quick-question/#findComment-339381
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.