SELECT gruppa, sum(hours) as nagruzka FROM list GROUP BY gruppa
And it is not NECESSARY to BORROW ANYTHING!
And just display this information with this request when required.
These are your constant iterations of the entire table with the entry in another - this is some kind of vestige left over from paper technologies. Get rid of them urgently and buy yourself a book on SQL.
Yes, and instead of mysql functions you have to use PDO.
$sql ="SELECT gruppa, sum(hours) as nagruzka FROM list GROUP BY gruppa"; $res = $pdo->query($sql)->fetchAll(PDO::FETCH_KEY_PAIR);
This code will return the desired $ res array to you, in which the keys will be the names of the groups, and the values will be their clock sum.
PDO is not necessary to be afraid, you just need to learn. Here is a good guide, http://phpfaq.ru/pdo
It shows that working with PDO is no more difficult than with mysql functions, especially considering that you didn’t have time to really learn them anyway.
Агрегирующие функции- u_mulder