Hi, guys!
I’m new there, I hope that will help me.
I use this poor way to make PHP to do what I want.
Fuction add/update information in mysql table, I use it to see, what users are doing in my website!
function addstats($action,$place){
$specips = array();
$specips[] = '127.10.0.1';
$timenow = time();
$myip = $_SERVER['REMOTE_ADDR'];
$myreferral = $_SERVER['HTTP_REFERER'];
if(!in_array($myip,$specips)){
$query = "SELECT a_id FROM actions WHERE a_ip = '$myip' AND a_place = '$place' AND a_action = '$action'";
$go = mysql_query($query);
$rows = mysql_num_rows($go);
$id = mysql_result($go,0,'a_id');
if($rows == 1)
{
$query = "UPDATE actions SET a_time2='$timenow', a_referral2='$myreferral', a_clicks=a_clicks+1 WHERE a_id = $id";
$go = mysql_query($query);
}
elseif($rows == 0)
{
$query = "INSERT INTO actions (a_ip, a_time1, a_time2, a_place, a_action, a_referral1, a_referral2, a_clicks)VALUES('$myip', '$timenow', '$timenow', '$place', '$action', '$myreferral', '$myreferral', '1')";
$go = mysql_query($query);
}
}
}
But I need to that function works faster, because in the mysql table will be around ~100 000 rows and that slows down website, it is possible to make it much faster and smaller?
I try to do that with “INSERT INTO actions … … ON DUPLICATE KEY UPDATE …”, but then there need to be more Primary keys, and all need to be Duplicate at the same time and then Update that row.
I try to find it in Google, but not found that what I need…
Sorry for bed English, I hope you Understand what I need and hope that will help me!