2
所以,讓我們舉一個例子,我有一個數據 Total Points is the sum of two points如何添加在PHP中使用不同的查詢兩種不同的行
現在我已經合併同名行,現在我需要做的是計算表兩個總點的總和(總和)並顯示在下一行中。這樣 Total of 'total points' 這裏是我的代碼
<table>
<tr align="center">
<td>Name</td>
<td>Point1</td>
<td>Point2</td>
<td>Total Points</td>
</tr>
<?php
$select_name = mysql_query("SELECT * FROM test");
while($row = mysql_fetch_array($select_name))
{
?>
<tr align="center">
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['point1']; ?></td>
<td><?php echo $row['point2']; ?></td>
<td><?php echo $row['point1']+$row['point2']; ?></td>
</tr>
<?php } ?>
<tr align="center">
<td>Name</td>
<td>Point1</td>
<td>Point2</td>
<td>Total Points</td>
</tr>
<?php
$select_name = mysql_query("SELECT DISTINCT name FROM test");
while($row = mysql_fetch_array($select_name))
{
$query_table1 = mysql_query("SELECT sum(point1) as sum1,sum(point2) as sum2, sum(point1)+sum(point2) as total FROM test WHERE name='".$row['name']."'");
?>
<tr align="center">
<td><?php echo $row['name']; ?></td>
<td><?php echo mysql_result($query_table1, 0, "sum1"); ?></td>
<td><?php echo mysql_result($query_table1, 0, "sum2"); ?></td>
<td><?php echo mysql_result($query_table1, 0, "total"); ?></td>
</tr>
<?php } ?>
<tr align="center">
<td>Total</td>
<td></td>
<td></td>
<td>???</td>
</tr>