Takes values from mySQL database and outputs the data with correct hierarchy