kevincro Posted December 5, 2007 Share Posted December 5, 2007 I'm trying to code a script that will search through my members list and return members who have the same IP address. What I need to know is what function do I use to find rows that have the same value for a field. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 5, 2007 Share Posted December 5, 2007 <?php $tablename = 'table'; $user_field = 'username'; $ip_field = 'ip_address'; // add your MySQL connection here $sql = "SELECT `$user_field`, `$ip_field` FROM `$tablename`"; if ( !$result = mysql_query($sql) ) { die('MySQL Error: ' . mysql_error()); } while ( list($user, $ip) = mysql_fetch_assoc($result) ) { echo 'Username: ' . $user . '<br>'; $sql = "SELECT `$user_field` FROM `$tablename` WHERE `$ip_field` = `$ip` AND `$user_field` != '$user' "; if ( !$result2 = mysql_query($sql) ) { die('MySQL Error: ' . mysql_error()); } if ( mysql_num_rows($result2) > 0 ) { while ( list($user2) = mysql_fetch_assoc($result2) ) { echo $user2 . 'has the same IP!<br>'; } } else { echo 'No duplicate IP found!<br>'; } echo '<br>'; } echo 'End of list'; ?> Will do the job... just fill in the 3 variables at the top and add your connection. Direct all 4 octet matches are rare... however you might want to adjust the script to test for the first 3 octets plus any 4th. That will give you some 'suspicious' results. PhREEEk Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.