php_stud
05-17-2004, 08:09 AM
Well, im back to php and right now, just trying to do a custom stat for my web... i know that there are lots of logfile analyzers, but i'm just trying to make this one work... First, php executes this code very slow, second it dont insert the matching records and the country to the last database connection...
thanks for any possible assistance here.
<?php
//---------------------------------------------------
// Sample code to display Visitor Country information
// PHP 4
//---------------------------------------------------
// Establishing a database connection
$db=mysql_connect("localhost","user","password");
mysql_select_db("hits",$db);
$all_records = "SELECT * from views WHERE date_visit='2004-05-13'";
$recordset = mysql_query($all_records,$db);
$myrow = mysql_fetch_array($recordset);
do{
$id = $myrow['id'];
$page = $myrow['page'];
$date_visit=$myrow['date_visit'];
$time_visit=$myrow['time_visit'];
$ip = $myrow['ip'];
mysql_select_db("country",$db);
// Query for getting visitor countrycode
$country_query = "SELECT country_name FROM iptoc WHERE IP_FROM<=inet_aton('$ip') AND IP_TO>=inet_aton('$ip') ";
// Executing above query
$country_exec = mysql_query($country_query);
// Fetching the record set into an array
$ccode_array=mysql_fetch_array($country_exec);
// getting the country name from the array
$country_name=$ccode_array['country_name'];
//Insert the matching record to the database
mysql_select_db("stats");
$sql2="INSERT INTO views (id,page,date_visit,time_visit,ip,country) VALUES ('$id','$page','$date_visit','$time_visit','$ip','$country')";
$result=mysql_query($sql2);
} while ($myrow=mysql_fetch_array($recordset));
?>
thanks for any possible assistance here.
<?php
//---------------------------------------------------
// Sample code to display Visitor Country information
// PHP 4
//---------------------------------------------------
// Establishing a database connection
$db=mysql_connect("localhost","user","password");
mysql_select_db("hits",$db);
$all_records = "SELECT * from views WHERE date_visit='2004-05-13'";
$recordset = mysql_query($all_records,$db);
$myrow = mysql_fetch_array($recordset);
do{
$id = $myrow['id'];
$page = $myrow['page'];
$date_visit=$myrow['date_visit'];
$time_visit=$myrow['time_visit'];
$ip = $myrow['ip'];
mysql_select_db("country",$db);
// Query for getting visitor countrycode
$country_query = "SELECT country_name FROM iptoc WHERE IP_FROM<=inet_aton('$ip') AND IP_TO>=inet_aton('$ip') ";
// Executing above query
$country_exec = mysql_query($country_query);
// Fetching the record set into an array
$ccode_array=mysql_fetch_array($country_exec);
// getting the country name from the array
$country_name=$ccode_array['country_name'];
//Insert the matching record to the database
mysql_select_db("stats");
$sql2="INSERT INTO views (id,page,date_visit,time_visit,ip,country) VALUES ('$id','$page','$date_visit','$time_visit','$ip','$country')";
$result=mysql_query($sql2);
} while ($myrow=mysql_fetch_array($recordset));
?>