I don't do a lot of coding, very infrequent, so I need some help with this.
I get a log file from my router and I have it parsed to specific IP address information and saved as a windows txt file. What I would like to do is have those IP address used to query a database that shows country of origin. For the final result I would like to have the IP address show and the country code next to it.
The connection to the database, the query and listing the IP addresses work fine. It is the trying to loop the query that I am having the issue. What am I doing wrong?
$file = fopen("ping.txt", "r"); //text file with any number of IP addresses
WHILE ($line = fgets($file)) {
for ($i=0;$i<count($line);$i++) {
$result = mysql_query("SELECT glc.glc_country
FROM geoip_blocks gbl
JOIN geoip_locations glc ON glc.glc_id = gbl.gbl_glc_id
WHERE gbl_block_start <= INET_ATON('$line[$i]')
ORDER BY gbl_block_start DESC
LIMIT 1")
or die (mysql_error());
//fetch the results
$cntry = mysql_fetch_row($result);
echo $line . $cntry . "<br />";
}
}
Any help will be greatly appreciated.