php select from table where condition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

php select from table where condition

Post by Vegan »

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

Code: Select all

<?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™
My site is powered by LAMP
Post Reply