Ti suggerisco di iniziare leggendo il manuale ufficiale:

http://www.php.net/mysql_fetch_assoc
http://www.php.net/mysql_num_fields e http://www.php.net/mysql_field_name
http://www.php.net/mysql_list_fields

Inoltre dovresti usare mysql_num_rows() al posto di mysql_affected_rows().