Hi,
I'm working on a flat-file db stat script and I need some help with it. The structure of the flat-file db is like this: for each user-statistic a different .dat file exists (e.g. browser.dat, screenresolution.dat etc.) For example the browser.dat file looks like this:
MIE5.0|10|5
NN4.51|2|2
OPERA6|5|3
where the first colums represents the browsertype, the second column are the total hits with this browser and the third one are the unique hits.
So far I've written a function that should register a user. Unfortunately it doesn't work as it should ... the script doesn't write the values to the .dat file. Where do I go wrong?
function AddStat($table, $new_value) {
$fp = file("$table.dat");
for ($i = 0; $i < count($fp); $i++)
{
$line = split("\|",$fp[$i]);
$value[$i] = $line[0];
$hits[$i] = $line[1];
$unique[$i] = $line[2];
}
for ($i = 0; $i < count($fp); $i++)
{
if ($new_value == $value[$i])
{
$match = "1";
break;
}
else $match = "0";
}
// Value is not recorded before.
if ($match == 0)
{
$i = count($fp)++;
$value[$i] = $new_value;
$hits[$i] = 1;
$unique[$i] = 1;
}
// Value is recorded before.
elseif ($match == 1)
{
$hits[$i]++;
$unique[$i]++;
}
$fp = fopen("$table.dat", w);
for ($i = 0; $i < sizeof($value); $i++)
{
$data = "$value[$i]|$hits[$i]|$unique[$i]\n";
$fout = fwrite($fp, $data);
}
fclose($fp);
}
I hope someone can help .... thanx Michiel