stats.php and the queries needed for it