Use a query like this: SELECT ip_address, count(*) AS n FROM my_table GROUP_BY ip_address HAVING n > 1
Doesn't seem to work... I have it like this: $error = mysql_query("SELECT ip, count(*) AS n FROM results GROUP_BY ip HAVING n > 1"); echo $error; Code (markup):
Try: $error = mysql_query("SELECT ip, count(*) AS n FROM results GROUP_BY ip HAVING n > 1"); while($array = mysql_fetch_assoc($error)): echo $array['ip']; endwhile; PHP:
I managed to do it like this: $double_ips = mysql_query('SELECT * FROM `results` where `ip` having COUNT(*) >= 2'); Code (markup): But that will return only the IP. I need all the results with double IPs. So, if we have ip1 and ip2 as double ips, I need to return like this: name1 ip1 name2 ip1 namen ip1 name1 ip2 name2 ip2 namen ip2
For that you will need to use a double query. $double_ips = mysql_query(' SELECT * FROM `results` WHERE `ip` IN ( SELECT `ip` FROM `results` WHERE `ip` HAVING COUNT(*) > 1) '); PHP: