Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2010
    Thanked 0 Times in 0 Posts

    how to query ip in p range

    I can't figure this. Can this be done alone with mysql, or there are somethings I need to do with php script.Let say I have many ip range stored in the database one of them is, - The table structure is like this

        ip                                                 customer name -                                name1 -                           name2
    Let say someone accessed a website and his ip is Now with this ip, it should get name1 from customer name column as it's is in the range of -
    Last edited by Anishgiri; 05-20-2014 at 11:20 AM.

  2. #2
    Super Moderator
    Join Date
    May 2005
    Southern tip of Silicon Valley
    Thanked 233 Times in 226 Posts
    That's a very poor way to store the IP ranges. You should split that into 2 fields such as start_IP and end_IP. It would also be better to store them as integers rather than strings.

    Assuming you made those changes, then the select statement would be:
    select customer_name from tablename where start_IP >= $IP and end_IP <= $IP;
    If you don't make those changes, then we might be able to work up a complex query that does what you want, but it wouldn't be very maintainable.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts