SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: ip's and mysql

  1. #1
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ip's and mysql

    Dear Sirs,
    I have a mysql table which stores the IP Address of my site visitors. I wish to sort these Ip address in the ascending or descending order. But when I do, the order is completely out of order. I am currently storing the addresses under a varchar column. An int column would not store the values after the second "."

    Can anyone tell me how I can fix this sorting problem?

    Thank you.

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post your code?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    .
    Last edited by kunal; Mar 3, 2002 at 16:33.
    i dunno...

  4. #4
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Seanf,
    Here is my code

    PHP Code:
    $sql "SELECT * FROM ip_stored ORDER BY ip_address desc";
    $query mysql_query($sql);
    while(
    $row mysql_fetch_array($query)) {
    echo 
    "$row[ip_address]<br>";

    Thats about all I am trying to do.

  5. #5
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just curious. Why do you need to sort your ip address?

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the table for IP your using?

    I like this idea... I want to use it, please!

    Can you e-mail me a txt file of the tables, adn a working NON-ordered IP code?

    That would be great!

    Thanks,
    ~someonewhois

    OH ya, my e-mail is tripleplay01@hotmail.com

  7. #7
    SitePoint Addict
    Join Date
    May 2001
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by johnn
    Just curious. Why do you need to sort your ip address?

    I need to sort the ip address. Why, because my boss asked me to

  8. #8
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just using a SELECT with DESC or ASC should sort the ip's lexicographically since they're VARCHAR type... why it won't work i don't understand... of course the periods "." could confuse things but much of it should be in order...

  9. #9
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A period mess everything up, I think. One way to do is you explode the ip address at "." then concat it before storing it. Now it's just a number.

    Hey, it may not be proper, but it's one way to do.

  10. #10
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Try using this query :

    SELECT * FROM ip_stored ORDER BY inet_aton(ip_address);

    This should the trick for you...

    kunal
    i dunno...


Bookmarks

Posting Permissions

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