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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.