How can I make below code to show grouping by country ranks in same div, example if in second loop rank 2nd must be show in same 2nd class div

How can I make below code to show grouping by country ranks in same div, example if in second loop rank 2nd must be show in same 2nd class div

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)