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!
<?php
//Geolocate users
include("geoip.inc");
include("geoipcity.inc");
include("geoipregionvars.php");
// Database settings
$db_host = 'localhost';
$db_user = 'user';
$db_pwd = 'password';
$database = 'sourcemod';
$table = 'player_tracker';
$connectdb = mysql_connect($db_host, $db_user, $db_pwd);
$selectdb = mysql_select_db($database);
$cell_get = mysql_query("SELECT playerip FROM player_tracker");
if (!$connectdb)
{
die ("Can't connect to database");
}
if (!$selectdb)
{
die ("Can't select database");
}
// read GeoIP database
//$country = geoip_open("GeoIP.dat", GEOIP_STANDARD);
//$city = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
//$record = geoip_record_by_addr($city, $country);
// map IP to city and country
//geoip_country_name_by_addr($country, $playerip) . " // < country code " . geoip_country_code_by_addr($country, $playerip) . " > ";
// sending query
$result = mysql_query("SELECT * FROM player_tracker");
if (!$result)
{
die("Query failed");
}
$fields_num = mysql_num_fields($result);
echo "<center><h1>All seeing eye</h1></center>";
echo "<center><table border=5 cellpadding=5 cellspacing=5><tr align=center valign=middle></center>";
echo mysql_result($cell_get, 2);
// print compulsory license notice
Print "<center><p> -- This page includes GeoIP data created by MaxMind, available from http://maxmind.com/ --</center>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr align=center valign=middle>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
// close database handler
//geoip_close($country, $city, $record);
mysql_free_result($result);
mysql_close($connectdb);
?>
This code prints a html table which contains the following columns from mysql table:
id
steamid
playerip
playername
city
country
password
joined
stats
servertype
serverip
status
How to do that values from 'playerip' column to be used for determining city and country and after that results to be:
1. shown in html table
2. inserted in mysql table after check for non-empty cells in city and country colums
There is a geoip partly working code... I think this can be used for retrieving city and country...
vertexshader wrote:
How to do that values from 'playerip' column to be used for determining city and country and after that results to be:
1. shown in html table
2. inserted in mysql table after check for non-empty cells in city and country colums
I dount know about your geo ip script-functions but i rewrite your code a little bit.
Now you can use playerip or what column ever in your script!
Thanks for cooperation but using your code gave me a new column 'country' after last one from database.
Maybe I think the correct question for this thread is "How to pick a data from cell at row X and print it in table in the same row?" ...