PHP - MySQL,排序克隆

发布于 2025-01-03 22:42:41 字数 201 浏览 0 评论 0原文

我有 mysql 数据库和表用户。在用户中有列:
id、username、password、ip

我有管理面板,我需要显示具有相同 ip 的用户,例如

User1 → User2

Nick1 → Nick2

等。

我如何使用 php 做到这一点。谢谢,以及这很紧急。谢谢。

I have mysql database with table users. In users there are columns:
id , username , password , ip

I have administration panel and I need to show users that have same ip , like this

User1 → User2

Nick1 → Nick2

etc.

How can i do it with php.Thanks , and this is urgent.Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人心善变 2025-01-10 22:42:41

这是您的 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)";

Here is your sql query.

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

For use in 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'];
}

UPDATE:

Try this query instead:

$sql = "SELECT username FROM users WHERE ip in 
(SELECT username FROM users GROUP BY ip HAVING count(ip) > 1)";
沫离伤花 2025-01-10 22:42:41

像这样获取重复 IP 的列表,
SELECT COUNT(*) as acount, ip FROM users GROUP BY ip HAVING acount > 1
然后使用这些结果,获取与这些 IP 匹配的所有帐户

Get your list of duplicate IP's like this,
SELECT COUNT(*) as acount, ip FROM users GROUP BY ip HAVING acount > 1
then using those results, get all accounts that match those IP's

冷情 2025-01-10 22:42:41
select users 
from users_table 
where ip ='thisIp'
select users 
from users_table 
where ip ='thisIp'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文