mySQL problem how to know the number of each color
I have database with images on it
example:
i have 5 of clothes images and from this 6 there are two images with blue color, 3 images with pink and the last one with green color.
and i have a search input , i want tell the user when he search for clothes the number of each color. i want the output 开发者_如何学JAVAlike this : blue(2) - pink(3) - green(1)
i know how to figure out the number of the word that he searched for it,
$query = mysql_query("SELECT * FROM images WHERE classification='$request'");
$num = mysql_num_rows($query);
but what i want is how to know the number of each color for the word that he searched for it.
Guessing from the query you provided, try a query like this:
SELECT color, COUNT(*) AS total FROM images WHERE classification='$request' GROUP BY color
精彩评论