You don't. The first code is PHP which is server side, and the second one is a client side link. The href in that link has to target a PHP script that is capable of calling countclick.
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php