Jump to content

IP Check issue


EchoFool

Recommended Posts

Hey,

 

 

I use this query to check if a user has a smiliar IP to another user... yet it doesn't work... me and my friends ip's have a match but the query returns 0 suggesting there was no IP match....

 

Can some one explain what i got wrong?

 

SELECT t1.IP 
     FROM iplogs t1
           INNER JOIN iplogs t2 ON t1.IP = t2.IP 
      WHERE t1.userID='$UserID1' AND t2.UserID='$UserID2' 
LIMIT 1

 

Table Example:

 

RecordIDIPUserID

111

112

Link to comment
https://forums.phpfreaks.com/topic/198943-ip-check-issue/
Share on other sites

If that's the case, then these queries will never return results unless the IPs are identical. Are you trying to see if they are similar as in 127.0.0.1 and 127.0.0.2 are close? If so, you'll have to use a function to split the IPs up, so it is only comparing 127.0.0 to 127.0.0.

Link to comment
https://forums.phpfreaks.com/topic/198943-ip-check-issue/#findComment-1044366
Share on other sites

Why are you using a join? I was under the impression a join was used to create a query using records from multiple tables...

 

"SELECT COUNT(*) FROM iplogs WHERE UserID=" . $UserID1 . " ORDER BY RecordID DESC"

 

If count is greater than 1, there are multiple users on that IP...

 

//EDIT

Typo

Link to comment
https://forums.phpfreaks.com/topic/198943-ip-check-issue/#findComment-1044368
Share on other sites

Andy-H no that doesn't really do what im looking for..

 

@ F1Fan

 

If you look at the above rows examples :

 

Table Fields:

Row 1:

RecordID  1

IP  127.0.0.1

UserID 1

 

Row 2:

RecordID 2

ID 127.0.0.1

UserID 2

 

There 2 match on IP and so should return 1

 

Because the where clause is checking if 2 users having a matching IPs at least once in the list of rows:

 

      WHERE t1.userID='$UserID1' AND t2.UserID='$UserID2'

Link to comment
https://forums.phpfreaks.com/topic/198943-ip-check-issue/#findComment-1044407
Share on other sites

SELECT t1.IP

    FROM iplogs t1

          INNER JOIN iplogs t2 ON t1.IP = t2.IP

      WHERE t1.userID='$UserID1' AND t2.UserID='$UserID2'

 

You are throwing userIDs at a query that is attempting to find duplicate ips.  You should run a different query, such that:

 

SELECT t1.IP
   FROM iplogs t1
       INNERJOIN iplogs t2 USING IP
   WHERE t1.userID != t2.userID

Link to comment
https://forums.phpfreaks.com/topic/198943-ip-check-issue/#findComment-1044422
Share on other sites

Got an error on syntax with that one,

 

SELECT t1.IP
FROM iplogs t1
INNER JOIN iplogs t2 ON ( t1.IP = t2.IP ) 
WHERE t1.userID != t2.userID

 

And I put this in:

 

SELECT t1.IP
FROM iplogs t1
INNER JOIN iplogs t2 ON ( t1.IP = t2.IP ) 
WHERE t1.userID =1
AND t2.userID =2

 

And I got IP=1

 

So I think the problem was with variables.

Link to comment
https://forums.phpfreaks.com/topic/198943-ip-check-issue/#findComment-1044433
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.