MY CODE: https://codeshare.io/WLlgxb
before i selected the totals and then looped through the fetched data, now i optimized the query to fetched data that i can use immediately.
I know i have a lot of loops but i dont know how to approach this otherwise
1