<?php

//work out what time a user is most online...
$morning = 0;
$noon = 0;
$night = 0;
if (isset($userid))
{
    $resultb=mysql_query("SELECT * FROM $forumtable WHERE strName = '$userid'");
}
else
{
    $resultb=mysql_query("SELECT * FROM $forumtable");
}
$num_rowsb = mysql_num_rows( $resultb );
while ( $b_row = mysql_fetch_object( $resultb ) )
{
    $thour = substr("$b_row->strTime", 0, 2);
    if ($thour <= 8 AND $thour >= 1)
    {
        $morning ++;
    }

    $thour = substr("$b_row->strTime", 0, 2);
    if ($thour <= 16 AND $thour >= 9)
    {
        $noon ++;
    }

    $thour = substr("$b_row->strTime", 0, 2);
    if ($thour <= 23 AND $thour >= 17 OR $thour == 0)
    {
        $night ++;
    }
}

if ($morning >= $noon AND $morning >= $night)
{
    $timer = $timermorning;
}
if ($morning < $noon AND $noon >= $night)
{
    $timer = $timernoon;
}
if ($night > $noon AND $morning < $night)
{
    $timer = $timernight;
}

print "$timer";