carlgcoder
carlgcoder

Reputation: 229

IP conflicts mysql

I am building a site where the users are allowed to have one account per IP.

I am looking for a way to display users with the same IP using PDO mysql...

Here is what I got...

$q = $dbc -> prepare ("SELECT login_ip FROM accounts");
$q -> execute();
$duplicate = $q -> fetch(PDO::FETCH_ASSOC);

This will fetch everyones' IP addresses. How can I then see if there is any exact matches and show them??

Upvotes: 1

Views: 83

Answers (1)

emboss
emboss

Reputation: 39650

SELECT login_ip, COUNT(login_ip) AS occurences
FROM accounts
GROUP BY login_ip
HAVING ( COUNT(login_ip) > 1 )

This will list you all possible duplicate IPs.

Upvotes: 4

Related Questions