$10 for a quick query

Discussion in 'Programming' started by Jac, Jan 15, 2011.

  1. #1
    i need somebody to help me with a little issue please.

    i have a script that connects to a database and matches their ip address then displays the result in the web browser, here is the code for that -

    <?php
    $server = 'localhost'; // MySQL hostname
    $username = 'username'; // MySQL username
    $password = 'password'; // MySQL password
    $dbname = 'dbname'; // MySQL db name


    $db = mysql_connect($server, $username, $password) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $sql = 'SELECT
    code
    FROM
    ip2nationCountries c,
    ip2nation i
    WHERE
    i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
    AND
    c.code = i.country
    ORDER BY
    i.ip DESC
    LIMIT 0,1';

    list($countryName) = mysql_fetch_row(mysql_query($sql));

    // Output Country Code
    echo $countryName;

    ?>



    What i want is a query that will display page1.php to anyone from the USA and page2.php to anyone from anywhere else in the world.

    The database im using is here

    i will pay somebody who posts the first working query
     
    Jac, Jan 15, 2011 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    $sql = 'SELECT
    code
    FROM
    ip2nationCountries c,
    ip2nation i
    WHERE
    i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
    AND
    c.code = 'us'
    ORDER BY
    i.ip DESC
    LIMIT 0,1';

    $sql = 'SELECT
    code
    FROM
    ip2nationCountries c,
    ip2nation i
    WHERE
    i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
    AND
    c.code != 'us'
    ORDER BY
    i.ip DESC
    LIMIT 0,1';

    Just from top of the head, didn't test it.
     
    hogan_h, Jan 15, 2011 IP
  3. Jac

    Jac Peon

    Messages:
    190
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    it didnt work mate, somebody suggested this, but that didnt work either

    <?php

    $server = 'localhost'; // MySQL hostname
    $username = 'username'; // MySQL username
    $password = 'password'; // MySQL password
    $dbname = 'dbname'; // MySQL db name


    $db = mysql_connect($server, $username, $password) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $sql = 'SELECT
    country_code
    FROM
    ip_group_country
    WHERE
    ip_start <=INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
    ORDER BY
    ip_start DESC
    LIMIT 0,1';
    list($CountryCode) = mysql_fetch_row(mysql_query($sql));

    ?>

    <?
    echo $CountryCode;
    ?>
     
    Jac, Jan 15, 2011 IP
  4. ssmm987

    ssmm987 Member

    Messages:
    180
    Likes Received:
    4
    Best Answers:
    3
    Trophy Points:
    43
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    Try this
    
    <?php
    
    $server = 'localhost'; // MySQL hostname
    $username = 'username'; // MySQL username
    $password = 'password'; // MySQL password
    $dbname = 'dbname'; // MySQL db name
    
    
    $db = mysql_connect($server, $username, $password) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    
    $sql = "SELECT
    `country_code`
    FROM
    `ip_group_country`
    WHERE
    `ip_start` <=INET_ATON('".$_SERVER['REMOTE_ADDR']."')
    ORDER BY
    `ip_start` DESC
    LIMIT 1';
    $query=mysql_query($sql)or trigger_error(mysql_error());
    list($CountryCode) = mysql_fetch_row($query);
    
    ?>
    
    <?
    echo $CountryCode;
    ?>
    
    PHP:
    If it doesn't work, it at least gives you some feedback about what exactly is wrong
     
    ssmm987, Jan 16, 2011 IP
  5. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    hogan_h, Jan 16, 2011 IP