在mysql中显示附加值 [英] Show added value in mysql
本文介绍了在mysql中显示附加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Awesome Programers在那里!
我需要你的帮助。我的代码有问题,我不知道如何在表格结果中制作出我想要的东西。
来自mysql的结果应该是这样的:( tvalue表示总值)
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
实施例:
的在MySQL或在数据库:
(5年级)
ID |年级| Math_Subj | English_Subj | History_Subj | P.E_Subj | Science_Subj
----------------------------------------- --------------------------------------------
1 | 5年级| 16 | 10 | 5 | 8 | 3
2 | 5年级| 2 | 6 | 8 | 3 | 5
(4年级)
ID |年级| Math_Subj | English_Subj | History_Subj | P.E_Subj | Science_Subj
----------------------------------------- --------------------------------------------
1 | 4年级| 8 | 11 | 8 | 5 | 4
2 | 4年级| 2 | 4 | 2 | 3 | 1
(3年级)
ID |年级| Math_Subj | English_Subj | History_Subj | P.E_Subj | Science_Subj
----------------------------------------- --------------------------------------------
1 | 3年级| 4 | 9 | 5 | 8 | 9
2 | 3年级| 7 | 4 | 3 | 1 | 2
表格结果并显示在页面中:
年级| Math_Subj | English_Subj | History_Subj | P.E_Subj | Science_Subj
----------------------------------------- -------------------------------------
5年级| 18 | 16 | 13 | 11 | 8
4年级| 10 | 15 | 10 | 8 | 5
3年级| 11 | 13 | 8 | 9 | 11
我尝试过:
<?php
$ con = mysqli_connect(localhost,test,abdub,test_table);
//检查连接
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}
$结果= mysqli_query($ CON,选择ID,(等级水平+ Math_Subj + English_Subj + History_Subj + P.E_Subj)AS总,水平级,Math_Subj,English_Subj,History_Subj ,P.E_Subj,FROM`Recote_show);
echo< table border ='1'>
< tr>
< th> ID< / th>
< th>等级级< /第>
将的第i; Math_Subj< /第>
将的第i; English_Subj< /第>
将的第i; History_Subj< /第>
将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);
?>
解决方案
con = mysqli_connect(localhost,test,abdub TEST_TABLE);
//检查连接
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}
结果= mysqli_query(
CON,选择ID,(等级水平+ 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>等级级< /第>
将的第i; Math_Subj< /第>
将的第i; English_Subj< /第>
将的第i; History_Subj< /第>
将th> P.E_Subj< / th>
< th> Science_Subj< / th>
< / tr>;
while(
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
What I have tried:
<?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); ?>
解决方案
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(
这篇关于在mysql中显示附加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文