Ti suggerisco di iniziare leggendo il manuale ufficiale:
http://www.php.net/number_format
http://www.php.net/sprintf
http://dev.mysql.com/doc/refman/5.0/...unction_format
Ti sarebbe utile anche leggere: http://php.html.it/guide/lezione/2986/sql-injections/