开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜