id manufacturer
1 nokia
2 sony ericsson
3 nokia
4 nokia
5 sony ericsson
6 motorola
7 sony ericsson
8 nokia
9 nokia
10 motorola
11 motorola
12 sony ericsson
question is, how can i return the result like the following:
nokia=5
sony erisson=4
motorola=3
i wanna get the total number of all the manufacturers that having the same name in a table... group 'em together and return the total...
tq!
Counting for the same manufacturer...
Moderator: General Moderators
Code: Select all
$result = mysql_query("SELECT * FROM table WHERE manufactures='nokia'");
$num_rows = mysql_num_rows($result);
echo 'nokia='.$num_rows.'';- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
If you store the manufacturer name in the phones table: this could shed some light.
If you store the id, or you have a seperate table with all the manufacturers:
If you store the id, or you have a seperate table with all the manufacturers:
Code: Select all
SELECT count( m.`id` ) `count`, m.`name`, m.`id`
FROM `manufacturers` m
LEFT JOIN `phones` p ON m.`id` = p.`manufaturer`
GROUP BY m.`id`Code: Select all
SELECT manufacturer, COUNT(*) as count
FROM manufacturers GROUP BY manufacturer;