Hello.

There is a table SUBJ. In it, the fields subj_id , subj_credit , result . Filled with:

 subj_id | subj_credit|result| 1 | 3 | 9 | 2 | 3 | 8 | 3 | 2 | 8 | 

Fulfilled it:

 $result = mysql_query("SELECT subj_id, subj_credit, result from subjects"); $credits = mysql_Fetch_array($result); 

According to the book, I understood that $ credit is an array. I need to do the following:

 RATING = (КРЕДИТ1*РЕЗУЛЬТАТ1 + КРЕДИТ2*РЕЗУЛЬТАТ2 + КРЕДИТ-N*РЕЗУЛЬТАТ-N)/СУММАКРЕДИТОВ 

Here CREDIT1, CREDIT2, etc. - these are results from subj_credit . RESULT1, RESULT2 - values ​​from result .

Tell me how to do it programmatically. I understood something like this:

  1. First, I count the number of records in the database: $kolvo = count($credits); read as long as there are records in the database.
  2. But then in the implementation I xs. ((

Where to dig at least.

    1 answer 1

     $result = mysql_query("SELECT subj_id, subj_credit, result from subjects"); $sum1=0; $kolvo=0; while ($result_row = mysql_fetch_array($result)) { $sum1 += $result_row['subj_credit'] * $result_row['result']; $kolvo++; } $credit = $sum1/$kolvo; 

    mysql_fetch_array returns an array in which the elements of a STRING each time it is called, or FALSE if it no longer exists.

    • The number can also be pulled out using the mysql_num_rows () function; $ kolvo = mysql_num_rows ($ result); - Yoharny Babay
    • Thank you all :) At night I did and dismantled :) - sollex