重复IP的mysql

need help. i have categories and COMMENTS inside with IP addresses. i need to check all of categories on repeated IP. if user use IP 2 times add css class (red) to user name, if use 3 times - another css class(green) , up to 5 times.

also i have container $comment['User']['ipaddress'] which show comment IP on site. how can i do this with sql claim ? thx

enter image description here

my connect to db:

$db = mysql_connect("localhost","root","root") OR DIE ('Ошибка подключения'); mysql_select_db("books", $db); $query = mysql_query("SELECT ipaddress FROM comments, $db); $res = mysql_fetch_array($query);

this code for one category. but i need to check all. And all user IP's are in one table.

if ($comment['User']['ipaddress'] == $res['ipaddress'])
    echo 'your ip repeated';
    else
    echo 'your ip is unique';

Try this:

SELECT ipaddress, count(ip) nb FROM comments GROUP BY pid, ipaddress HAVING nb>1