ma sei certo che row[tot] corissponda a mysql_num_rows?

Posta la query $sql2