Jump to content

[SOLVED] Skipping rows containing similar information in the DB.


pocobueno1388

Recommended Posts

Okay...I have an inventory script where users buy items from a store and the item is added to they're inventory. They can buy as many as the same item as they want. I have no problem displaying all the items in they're inventory, the problem is how I want it setup.

This is how it is set up right now: [I am just making up example items]

--ipod---    --book--  --ipod--  --ipod--

You see how there are 3 of the same items being displayed (3 ipods)? I would like it to look like this:

--ipod--            --book--
Amount: 3        Amount: 1

Instead of just displaying each item individually.

Here is how the database is set up:

TABLE items
itemID (unique field)
ownerID (the owner of the item)
item_name

How exactly would I get this done?

Thanks in advance  :)

Okay, I think thats going to work great, but how exactly would I print out the amount?

[code]
<?php

$get_items = mysql_query("SELECT count(iname) as c, items.iname from items WHERE ownerid='$sid' group by iname");

  while ($item = mysql_fetch_assoc($get_items)){

      echo "{$item['iname']}<br>";

      //****I would like to echo the amount they have right here.*****

  }
}

?>
[/code]
[code]$get_items = mysql_query("SELECT count(iname) as c, items.iname from items WHERE ownerid='$sid' group by iname");[/code]


pay attention to the [code]count(iname) as c[/code]

This is creating an alias for that value


[code]echo "{$item['c']}<br>";[/code]

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.