made sql functions and made on accompanying php