Obligatory suggestion, Don't use mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
You should change the function name to get_total hits, as it makes no sense, and the scope of the database connection wont be available within functions, your need to pass it to it or use global to access it, this makes it bad practice but for example
<?php
function get_total_hits(){
global $db; // or whatever the variable for mysql_connect() is