私は訪問者のIPのmysqlデータベースを持っており、それらのIPのいくつがX国からのものであるかを示すHTMLテーブルを作成しようとしています。訪問者がどの国から来たのかを示すスクリプトを取得することはできますが、行ごとではなくグループで表示する方法が見つからないようです。
たとえば、現在私は次のようになっています。
Country | Visitors
------------------
US | Array
UK | Array
UK | Array
UK | Array
US | Array
MX | Array
MX | Array
私が欲しいのは:
Country | Visitors
------------------
US | 2 Visitors
UK | 3 Visitors
MX | 2 Visitors
試しましarray_count_values
たが、それでもすべての訪問者が行ごとに一覧表示され、すべての行に「配列」の値が割り当てられます。
IPはデータベースにあり、スクリプトはIPをプルしてから、別のファイルのデータに基づいてIPに国コード値を割り当てます。
これが私のアマチュアスキルでハックしたものです。これを達成するためのより良い方法があれば、提案を歓迎します!
require_once("geoip.inc");
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
include_once($_SERVER['DOCUMENT_ROOT'] . 'connect.php');
/* Performing SQL query */
$data = mysql_query("SELECT * FROM the_ips LIMIT 100")
or die(mysql_error());
echo "<table>";
echo "<td><strong>Country</strong></td><td><strong>Visitors</strong></td></tr>";
while($info = mysql_fetch_array( $data ))
{
$ip = $info['ip_address'];
$country_code = geoip_country_code_by_addr($gi, $ip);
$countrylist = array($country_code);
$frequency = array_count_values($countrylist);
echo "<tr><td style='width: 100px;'>".$country_code."</td><td style='width: 100px;'>".$frequency."</td></tr>";
}
echo "</table>";
geoip_close($gi);