Fixed the "View Visit" page SQL queries