我试图在数据库中找到所有具有相同ip的用户
我尝试了几种方法。
现在我正在尝试这个,但它只给了我一个用户
这是我的PHP代码的简短示例:
<?php
$CheckQuery = mysqli_query($GLOBALS["___mysqli_ston"],
"SELECT * FROM `logedfeeds`
WHERE ip='127.0.0.1'
GROUP BY user_id
ORDER BY `id`
DESC LIMIT 1000000");
//create table
$step1 = '<center><table border="1"><tr><td><b>UserID</b></td></tr>';
while($row = mysqli_fetch_assoc($CheckQuery)){
$userip = $row['user_id'];
$step2 = '<tr><td>' . $userip . '</td></tr>';
}
echo "$step1 $step2 </table></center>";
?>
我正在尝试使用此代码,但似乎无法正常工作。
答案 0 :(得分:0)
尝试此查询:
SELECT * FROM logedfeeds
WHERE ip LIKE '%127.0.0.1%'
GROUP BY user_id
ORDER BY id
DESC LIMIT 1000000
答案 1 :(得分:0)
您正在覆盖$step2
变量
更改您的代码,使其成为
<?php
$CheckQuery = mysqli_query($GLOBALS["___mysqli_ston"],
"SELECT * FROM `logedfeeds`
WHERE ip='127.0.0.1'
GROUP BY user_id
ORDER BY `id`
DESC LIMIT 1000000");
//create table
$step1 = '<center><table border="1"><tr><td><b>UserID</b></td></tr>';
$step2 = '';
while($row = mysqli_fetch_assoc($CheckQuery)){
$userip = $row['user_id'];
$step2 .= '<tr><td>' . $userip . '</td></tr>';
}
echo "$step1 $step2 </table></center>";
?>
首先在while循环之外声明$step2
变量并保持连接,然后在循环外回显它。