Querying MySQL to search for array data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Whittaker

    Querying MySQL to search for array data

    Hello!

    I have a problem with my php script.
    The script's task is to search an IP-Database with ranges as entries
    and find, in which range the entered IP is.

    OK, I've queried the MySQL-Results of the ranges into an array,
    containing the
    "IP ==> internalid"
    where internalid is the Primarykey of the table from which I can get
    more infomation about that range at a later point.

    The IP can be found in a range and so on.. Everythong works. But: How
    can I search the database for more than one entry, when the IP exists
    in more than one range?

    I really don't know how to do that, maybe my energy is nearly at "0"
    now, so it would be very nice, if you could help me =)

    Greetings, Michael Whittaker.
    Germany
  • Nikolai Chuvakhin

    #2
    Re: Querying MySQL to search for array data

    fisherman@it-tec.net (Michael Whittaker) wrote in message
    news:<1aacbe0a. 0408060301.21a8 f264@posting.go ogle.com>...[color=blue]
    >
    > The IP can be found in a range and so on.. Everythong works. But: How
    > can I search the database for more than one entry, when the IP exists
    > in more than one range?[/color]

    Use a simple OR clause:

    SELECT * FROM the_table
    WHERE IP [condition 1] OR IP [condition 2];

    Cheers,
    NC

    Comment

    • steve

      #3
      Re: Re: Querying MySQL to search for array data

      "Nikolai Chuvakhin" wrote:[color=blue]
      > fisherman@it-tec.net (Michael Whittaker) wrote in message
      > news:<1aacbe0a. 0408060301.21a8 f264@posting.go ogle.com>...[color=green]
      > >
      > > The IP can be found in a range and so on.. Everythong works. But:[/color]
      > How[color=green]
      > > can I search the database for more than one entry, when the IP[/color]
      > exists[color=green]
      > > in more than one range?[/color]
      >
      > Use a simple OR clause:
      >
      > SELECT * FROM the_table
      > WHERE IP [condition 1] OR IP [condition 2];
      >
      > Cheers,
      > NC[/color]

      And just in case you don’t know, you can use the LIKE to search for
      partial ip matches. See mysql manual for LIKE.

      --
      http://www.dbForumz.com/ This article was posted by author's request
      Articles individually checked for conformance to usenet standards
      Topic URL: http://www.dbForumz.com/PHP-Querying...ict137185.html
      Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=458630

      Comment

      • Chung Leong

        #4
        Re: Querying MySQL to search for array data

        "Michael Whittaker" <fisherman@it-tec.net> wrote in message
        news:1aacbe0a.0 408060301.21a8f 264@posting.goo gle.com...[color=blue]
        > Hello!
        >
        > I have a problem with my php script.
        > The script's task is to search an IP-Database with ranges as entries
        > and find, in which range the entered IP is.
        >
        > OK, I've queried the MySQL-Results of the ranges into an array,
        > containing the
        > "IP ==> internalid"
        > where internalid is the Primarykey of the table from which I can get
        > more infomation about that range at a later point.
        >
        > The IP can be found in a range and so on.. Everythong works. But: How
        > can I search the database for more than one entry, when the IP exists
        > in more than one range?
        >
        > I really don't know how to do that, maybe my energy is nearly at "0"
        > now, so it would be very nice, if you could help me =)
        >
        > Greetings, Michael Whittaker.
        > Germany[/color]

        Might make sense to store the IP range as integers. Then you can do a simple[color=blue]
        >= and <= comparison. Use ip2long to convert a ###.###.###.### address into[/color]
        a 32bit integer.


        Comment

        • Michael Whittaker

          #5
          Re: Querying MySQL to search for array data

          Hi!

          Thanks for you replies!
          The IPs are already stored in integer format... But one question btw:
          Does php generate negative integers too? Or does the ip2long-function
          start with "0"?

          I'll try the OR and LIKE-queries tomorrow and will tell you if it
          solved my problem :)

          Thanks again!
          Michael Whittaker.

          "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<ucqdnZ6K4 IkkxoncRVn-ug@comcast.com> ...[color=blue]
          > "Michael Whittaker" <fisherman@it-tec.net> wrote in message
          > news:1aacbe0a.0 408060301.21a8f 264@posting.goo gle.com...[color=green]
          > > Hello!
          > >
          > > I have a problem with my php script.
          > > The script's task is to search an IP-Database with ranges as entries
          > > and find, in which range the entered IP is.
          > >
          > > OK, I've queried the MySQL-Results of the ranges into an array,
          > > containing the
          > > "IP ==> internalid"
          > > where internalid is the Primarykey of the table from which I can get
          > > more infomation about that range at a later point.
          > >
          > > The IP can be found in a range and so on.. Everythong works. But: How
          > > can I search the database for more than one entry, when the IP exists
          > > in more than one range?
          > >
          > > I really don't know how to do that, maybe my energy is nearly at "0"
          > > now, so it would be very nice, if you could help me =)
          > >
          > > Greetings, Michael Whittaker.
          > > Germany[/color]
          >
          > Might make sense to store the IP range as integers. Then you can do a simple[color=green]
          > >= and <= comparison. Use ip2long to convert a ###.###.###.### address into[/color]
          > a 32bit integer.[/color]

          Comment

          Working...