count and fetch rows in php

Posted by Mac Taylor on Stack Overflow See other posts from Stack Overflow or by Mac Taylor
Published on 2010-04-27T12:15:05Z Indexed on 2010/04/27 12:23 UTC
Read the original article Hit count: 250

Filed under:
|

hey guys

i have a table in my mysql database named (names) now everyone can save their real names

now i want to query this table and find out how many times these names used

forexample the output should be :

Jakob (20) Jenny (17)

now this is my own code :

    list($usernames) =mysql_fetch_row(mysql_query('SELECT name FROM table_user GROUP BY name ORDER BY COUNT(name) DESC LIMIT 50 '));
    list($c) =mysql_num_rows(mysql_query('SELECT COUNT(name) FROM table_user GROUP BY name '));

    print $usernames.'('.$c.')'

is this a correct approach ?!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql