pocobueno1388 Posted January 30, 2007 Share Posted January 30, 2007 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: 1Instead of just displaying each item individually.Here is how the database is set up:TABLE itemsitemID (unique field)ownerID (the owner of the item)item_nameHow exactly would I get this done?Thanks in advance :) Link to comment https://forums.phpfreaks.com/topic/36279-solved-skipping-rows-containing-similar-information-in-the-db/ Share on other sites More sharing options...
ninja Posted January 30, 2007 Share Posted January 30, 2007 SELECT count(item_name) as c, items.* from items group by item_name Link to comment https://forums.phpfreaks.com/topic/36279-solved-skipping-rows-containing-similar-information-in-the-db/#findComment-172489 Share on other sites More sharing options...
pocobueno1388 Posted January 30, 2007 Author Share Posted January 30, 2007 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] Link to comment https://forums.phpfreaks.com/topic/36279-solved-skipping-rows-containing-similar-information-in-the-db/#findComment-172498 Share on other sites More sharing options...
chronister Posted January 30, 2007 Share Posted January 30, 2007 [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] Link to comment https://forums.phpfreaks.com/topic/36279-solved-skipping-rows-containing-similar-information-in-the-db/#findComment-172520 Share on other sites More sharing options...
pocobueno1388 Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks guys ^^ Link to comment https://forums.phpfreaks.com/topic/36279-solved-skipping-rows-containing-similar-information-in-the-db/#findComment-172658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.