PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Oct 18, 2017 2:28 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Feb 13, 2017 1:30 pm 
Offline
Forum Contributor

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 486
Location: Victoria, BC
Now that I have manually created my databases and I have stuffed some data into them

given i have the IP address of the user, I wanted to select the country from the table where the ip is found

this reference is the whole enchilada which is more than need

SELECT [COUNTRY NAME COLUMN], [REGION NAME COLUMN], [CITY NAME COLUMN], [LATITUDE COLUMN], [LONGITUDE COLUMN], [ZIP CODE COLUMN], [TIME ZONE COLUMN], [ISP COLUMN], [DOMAIN NAME COLUMN], [NETSPEED COLUMN], [IDD CODE COLUMN], [AREA CODE COLUMN], [WEATHER STATION CODE COLUMN], [WEATHER STATION NAME COLUMN], [MCC COLUMN], [MNC COLUMN], [BRAND NAME COLUMN]
FROM [IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE TABLE]
WHERE [SEARCH IP NO] BETWEEN [IP FROM COLUMN] AND [IP TO COLUMN]

my code is incomplete, which is why I need to suggestions

Syntax: [ Download ] [ Hide ]
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "ip2location";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT country_code FROM ip2location_db1 WHERE " + $ip + " BETWEEN ip_from AND ip_to";
$result = $conn->query($sql);
?>
 


the idea was to get a 2 letter country code I could feed to a switch statement, the country code is a 2 letter result, there is also another field with the full name that is not important for my present needs

_________________
Hardcore Games Legendary is the Only Way to Play!
Vegan Advocate 16 lbs grain to make only 1 lb meat, water for 6 months of showers and 34.1 lbs carbon dioxide
My sites are made with WordPress, which is a content management system, Joomla and Drupal are some alternatives


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group