<?php
function cal_avgscore($aid){
	global $db,$tblprefix;
	if(!$aid) return;
	if($row = $db->fetch_one("SELECT COUNT(*) AS counts,AVG(score) AS avgscore FROM {$tblprefix}comments WHERE aid='$aid'")){
		$db->query("UPDATE {$tblprefix}archives SET scores = '$row[counts]',avgscore = '".round($row['avgscore'],2)."' WHERE aid='$aid'");
	}
	unset($row);
}

?>
