Fixed HTML, added mysql function instead of JOIN queries