Показать добавленную стоимость в mysql
Hello Awesome Programers there! I need your help please. I have problem in my codes, I don't know how I could make the things I want to be in my tables results. The result from mysql it should be like this: (tvalue means total value) th_name1 | th_name2 | th_name3 | th_name4 | th_name_5 | th_name6 ------------------------------------------------------------------------------------- th_scope_row1 |td_tvalue2.1 |td_tvalue3.1 |td_tvalue4.1 |td_tvalue5.1 |td_tvalue6.1 th_scope_row2 |td_tvalue2.2 |td_tvalue3.2 |td_tvalue4.2 |td_tvalue5.2 |td_tvalue6.2 th_scope_row3 |td_tvalue2.3 |td_tvalue3.3 |td_tvalue4.3 |td_tvalue5.3 |td_tvalue6.3 Example: In mysql or in database: (Grade 5) ID | Grade level | Math_Subj | English_Subj | History_Subj | P.E_Subj |Science_Subj ------------------------------------------------------------------------------------- 1 | Grade 5 | 16 | 10 | 5 | 8 | 3 2 | Grade 5 | 2 | 6 | 8 | 3 | 5 (Grade 4) ID | Grade level | Math_Subj | English_Subj | History_Subj | P.E_Subj |Science_Subj ------------------------------------------------------------------------------------- 1 | Grade 4 | 8 | 11 | 8 | 5 | 4 2 | Grade 4 | 2 | 4 | 2 | 3 | 1 (Grade 3) ID | Grade level | Math_Subj | English_Subj | History_Subj | P.E_Subj |Science_Subj ------------------------------------------------------------------------------------- 1 | Grade 3 | 4 | 9 | 5 | 8 | 9 2 | Grade 3 | 7 | 4 | 3 | 1 | 2 Table result and shows in page: Grade level | Math_Subj | English_Subj | History_Subj | P.E_Subj |Science_Subj ------------------------------------------------------------------------------ Grade 5 | 18 | 16 | 13 | 11 | 8 Grade 4 | 10 | 15 | 10 | 8 | 5 Grade 3 | 11 | 13 | 8 | 9 | 11
Что я уже пробовал:
<?php $con=mysqli_connect("localhost","test","abdub","test_table"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT id,( Grade level + Math_Subj + English_Subj + History_Subj + P.E_Subj ) AS total, Grade level, Math_Subj, English_Subj, History_Subj, P.E_Subj, FROM `Record_show"); echo "<table border='1'> <tr> <th>ID</th> <th>Grade level</th> <th>Math_Subj</th> <th>English_Subj</th> <th>History_Subj</th> <th>P.E_Subj</th> <th>Science_Subj</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Grade_5'] . "</td>"; echo "<td>" . $row['Grade_4'] . "</td>"; echo "<td>" . $row['Grade_3'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?>