move sql in the template into index.php