Been working on some code to find all the duplicate IP's in the system. I have spent an entire day almost non stop and can't get the thing figured out. Here is what I am trying:
Code: Select all
$sql = "SELECT reg_ip, COUNT(*) as count, username FROM users WHERE reg_ip = '$ip' GROUP BY reg_ip HAVING COUNT(*) > 1";
$user_query = mysqli_query($db_lqls, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
echo "<td>".$row['reg_ip']."</td>";
}
Basically I have a search form that I"ve created to do an IP search from the database; Admin enters an IP address. I need it to give me all the duplicates in it if it finds that it's a duplicate IP. I was just going to try and get the IP's first and then try to add usernames to match them.
My search form is search IP, and then I turn that from the POST searchip to the $ip to use in the code above: WHERE reg_ip = $ip.....
When I echo it, it shows the IP that is duplicated, but it doesn't show all the rows of all the other IP's that are duplicated. Like I have 4 users with the same IP in the database, but it only shows one IP instead of displaying all four rows.... Any Ideas?
Ultimately I need it to do a search from the form and then grab the POST form name and then show every username that has the same IP address in the database...