List:General Discussion« Previous MessageNext Message »
From:Jake Peavy Date:March 27 2006 8:07pm
Subject:Re: Comparing x.x.x.x strings
View as plain text  
On 3/27/06, Lucas Vendramin <lucas.vendramin@stripped> wrote:
>
> Thank you.
> The INET_ATON() function works fine. :D
> I hope this solution save me.
> Thanks.
>
> > Take a look at the MySQL function INET_ATON and it's counterpart (I
> don't
> > remember what it's counterpart is but it should be easy to find once you
> > find INET_ATON).
> >
> > I know in PHP there is a function that will convert x.x.x.x to an int
> and
> > then you just put that int into a field in your database and then use
> the
> > INET_ATON function in MySQL to select the ips you want.
> >
> > SELECT INET_ATON('3.2.0.13') > INET_ATON('3.2.0.2')
> >
> > That should return TRUE. :)
> >
> > Hope that helps.
> >
>
> > On 3/24/06 2:44 PM, "Lucas Vendramin" <lucas.vendramin@stripped> wrote:
> >
> >> Hi all.
> >> I have a problem:
> >> When I compare two strings in mask (x.x.x.x) the comparation is not
> true
> >> (for
> >> my question :D)... look:
> >>  select '3.2.0.13' > '3.2.0.2'            -> FALSE
> >> I want this command return TRUE, but it is returning FALSE.
> >> But, if I put a space first into the smaller string the camparation
> will
> >> returns what I want:
> >>  select '3.2.0.13' > ' 3.2.0.2'            -> TRUE
> >>
> >> How can I check it? There is a way to correct my problem? The string is
> >> like a
> >> IP-ADDRESS where 192.168.0.13 is better than 192.168.0.2, but it is not
> a
> >> IPADDRESS column, it is a Version of file (version 3.2.0, version 3.2.1
> ,
> >> etc...)


Note that your version numbers will have to remain formatted as 4 dotted
decimals or that function will throw an error.  You may have to 0-fill
unused "octets" (such as version 4.0.0.0 instead of simply version 4.0)

In addition, your version numbers will have to be IP-like -- for example a
version of 2.2.0.918 will error.


--
> -jp

Thread
Comparing x.x.x.x stringsLucas Vendramin24 Mar
  • Re: Comparing x.x.x.x stringsRhino24 Mar
    • Re: Comparing x.x.x.x stringsPeter Brawley25 Mar
  • Re: Comparing x.x.x.x stringsJay Paulson24 Mar
    • Re: Comparing x.x.x.x stringsLucas Vendramin27 Mar
      • Re: Comparing x.x.x.x stringsJake Peavy27 Mar
  • Re: Comparing x.x.x.x stringsDan Nelson24 Mar