There is a table with groups, objects, and the number of hours.

enter image description here

As a result of the algorithm, you should get the following

enter image description here As you can see from the illustration, I managed to implement it. BUT! The implementation took place only on one condition.

$bd = mysql_query("SELECT * FROM list WHERE profile='Менеджмент' AND discipline='Информатика'"); while ($myrow = mysql_fetch_assoc($bd)) { $res = $myrow['type']; if ($res == 'Лекция') { $lec = $lec + $myrow['count_hours']; $countgroup++; $countstudents = $countstudents + $myrow['count_students']; } if ($res == 'Семинар') { $seminar = $seminar + $myrow['count_hours']; } if ($res == 'Лабораторная') { $lab = $lab + $myrow['count_hours']; $countpodgroup++; } $discipline = $myrow['discipline']; $profile = $myrow['profile']; $course_semestr = $myrow['course_semestr']; } $bde = mysql_query("UPDATE result SET id='$id', discipline='$discipline', profile='$profile', course_semestr='$course_semestr', count_students='$countstudents', count_group='$countgroup', count_podgroup='$countpodgroup', lectures='$lec',seminar='$seminar',lab='$lab'"); 

In the table, in addition to MANAGEMENT, there will be other meanings (Psychology, Computer Science, etc.) Therefore, you need to write an algorithm so that it shares these values, rather than adding them together. I understand that you need to wrap all this in a cycle?

  • Please indicate what you have tried and what did not work out? As I understand it, this is an educational task? - Timofei Bondarev
  • Not at all. This task is actually with a large number of fields, and calculations. I just need to understand the principle of work, and apply it in my project. In order not to paint all the fields that are in my project, I decided not to embroil you in my definitions, but to bring it all on a simple illustrative example - Shamil Aslanov
  • In this case, it is necessary to reformulate the condition and the title so that it is easier for the reader to understand the problem. Add a short text description to the question. - Timofei Bondarev
  • Good, second - Shamil Aslanov

1 answer 1

This is called a pivot, a description of the principle here. If the set of items is dynamic, then a discussion of possible solutions is here .

  • I did not know that this is called "pivot". It will be necessary to read. Thank you - Shamil Aslanov