Hi guys,
My math is letting me down a bit and i am hoping someone here can help me.
Basicly i am trying to display the time spent on my site and the time spent on each section of the site. The site is built in flash and all the tracking is working as it should. It just tallying up the time is proving to be a headache.
When someone enter the site the tracker gets there ip and add's it to the db with timestamp. When the user continues to navigate the site the sections they visit are recorded in the db with timestamp and section id. This is the same for when they leave that section.
Below is the code i am using to retrieve the results.
for($i=0; $i < $lastTen; $i++) {
$visitorsD = mysql_fetch_array($visitorsC);
$visitorPagesA = mysql_query("SELECT * FROM visits WHERE uid = '".$visitorsD['id']."' ORDER BY id") or die(mysql_error());
$output .= "&lastTen" . $i . "numViews=" . mysql_num_rows($visitorPagesA);
$output .= "&lastTen" . $i . "lastVisit=" . $visitorsD['date'] . " " . $visitorsD['time'];
$output .= "&lastTen" . $i . "country=" . ucWords(strToLower($visitorsD['country']));
$output .= "&lastTen" . $i . "browser=" . $visitorsD['browser'];
$output .= "&lastTen" . $i . "os=" . $visitorsD['operatingSystem'];
$output .= "&lastTen" . $i . "entry=" . $visitorsD['entryPage'];
//---------------------------------------------------------------------------------
$totTime = 0;
$totalTime = 0;
$time = 0;
//---------------------------------------------------------------------------------
$userPageDate = split("/",$visitorsD['date']);
$dateID = $userPageDate[2]."-".$userPageDate[1]."-".$userPageDate[0];
$visitorPages = mysql_query("SELECT * FROM userpages WHERE dateClicked = '".$dateID."' && ip ='".$visitorsD['ip']."'") or die(mysql_error());
$pagesClicked = mysql_num_rows($visitorPages);
for($l = 0; $l < $pagesClicked; $l++){
$clicked = mysql_fetch_array($visitorPages);
//Time in section
$time = round($clicked['timeOnPage'] - $clicked['timeClicked'],1);
//Total time on site taking from adding time on section together
$totTime += $time;
//if time is less than 60 then treat as seconds
if($time<60){
$pageTime = $time." secs";
}else{
// if greater than 60 then dived and treat as minutes
$pageTime= round($time/60,1);
if($pageTime<60){
$pageTime=$pageTime."mins";
}else{
$pageTime= round($pageTime/60)."mins";
}
}
$output .= "&lastTen" . $i . "pages" . $l . "pageTitle=" . $clicked['pageID'];
$output .= "&lastTen" . $i . "pages" . $l . "pageTime=" . $pageTime;
}
if($totTime < 60) {
$output .= "&lastTen" . $i . "totalTime=" . $totTime . " mins";
} else {
$mins= round($totTime/60);
if($mins<60){
$output .= "&lastTen" . $i . "totalTime=" .$mins . " mins";
}else{
$mins= round($mins/60);
$output .= "&lastTen" . $i . "totalTime=" .$mins . " mins";
}
}
$output .= "&lastTen" . $i . "pagesClicked=". $pagesClicked;
}
Can anyone point out where i am going wrong