我有表用户的mysql数据库。在用户中有列:
id , username , password , ip
我有管理面板,我需要显示具有相同IP的用户,例如
User1→User2
Nick1→Nick2
等
我怎么能用php.Thanks做这件事,这很紧急。谢谢。
答案 0 :(得分:1)
这是你的SQL查询。
SELECT username, list.ip FROM users
INNER JOIN (SELECT ip FROM users
GROUP BY ip HAVING count(id) > 1) dup ON list.ip = dup.ip
用于PHP:
$sql = "SELECT username, list.ip FROM users
INNER JOIN (SELECT ip FROM users
GROUP BY ip HAVING count(id) > 1) dup ON list.ip = dup.ip";
$result = mysql_query($sql,$con);
while($row = mysql_fetch_array($result))
{
echo $row['username'];
}
<强>更新强>
请尝试此查询:
$sql = "SELECT username FROM users WHERE ip in
(SELECT username FROM users GROUP BY ip HAVING count(ip) > 1)";
答案 1 :(得分:0)
select users
from users_table
where ip ='thisIp'
答案 2 :(得分:0)
获取这样的重复IP列表,
SELECT COUNT(*) as acount, ip FROM users GROUP BY ip HAVING acount > 1
然后使用这些结果,获得与这些IP匹配的所有帐户