if($index=0)

Manca un uguale. Con quest'istruzione fai un'assegnazione, non un confronto. Quindi sarà sempre vera.

mysql_affected_rows() inoltre

Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated
mentre per il numero di righe restituito da una select devi usare mysql_num_rows().

Usa inoltre il tag php o code quando posti al fine di rendere più agevole la lettura del codice agli altri utenti.