Hi,
I have a mysql database and one table is a 'product' table.
This table consists of product names, prices and types.
What i would like to be able to do is display a list of each product type that is different.
For example:
product table consists of
Name Price Type
------------------------------------------------------
giraffe £1.00 mask
lion £1.00 mask
whistle £2.00 toy
ball £1.50 toy
t-shirt £5.50 clothing
------------------------------------------------------
I want to be able to display a list of each different product type.
e.g. from the table above the list would look like:
List
--------------
mask
toy
clothing
--------------
How can i do this?
select from loop
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
select * from table where type = 'toy'
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
ooooh ok
Code: Select all
$types = array('toy','clothing','mask');
foreach($types AS $type){
SELECT * FROM `table` WHERE `type` = $type;
}
// or
// kidna guessing on this one, sorry
SELECT * FROM `table` GROUP BY `type`Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT DISTINCT `type` FROM `table`