/*Counting function
$table table name
$counname counting storage field
$idname ID field name
$id queried ID number
$view save or view the number
Author: microrain
Homepage: http://www.codechina.net
Email: web@codechina.net
*/
function counter($table,$counname,$ idname,$id,$view) {
//Query the current number of views
$sql="select * from $table where $idname=$id";
$result=mysql_query($sql);
$objresult=mysql_fetch_object($result);
$count=$objresult->$counname;
//Update the database and return the current number of views as the result
$count2=$count+ 1;
if($view){
$sql="update $table set $counname=$count2 where $idname=$id";
mysql_query($sql);
}
return $count2;
}
?>