Can't get SQL query results
A template file should never contain code that executes a query; that should be done in a preprocess function, eventually. 

The code to get the number of rows in a table is similar to the following one.

$count = db_result(db_query("SELECT COUNT(*) FROM {mytable}"));


The table name should always be put between curly brackets, which will be replaced with the prefix currently set for database tables.