如何对表的行和列求和

如何对表的行和列求和

本文介绍了如何对表的行和列求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 id      fes     bus    snacks    other   total
 =============================================
 1      400     200     50        20      670
 =============================================
 2      350     100     20        0       470
 ==============================================
TOTAL = 750     300     70        290     1140
 =============================================







pls how can i create this kind of  table? where id=1 has its total at the end of the row e.g   id=1 has 400 + 200 + 50 + 20 = 670 and also fees has its total at the end of its the column e.g 400 + 350 = 750
and this should apply to all the table records i will appreciate html, php and sql codes,i am a learner thanks
<pre>
<pre>am so new here! pls pardon my english,





我的尝试:





What I have tried:

<table width="100%">
		  <tr>
			<th >S/N</th> 
			<th>fes</th>
			<th>bus</th>
			<th>snacks</th>
			<th>other</th>
                        <th>total</th>
		  </tr>
		  
		  <?php 
		  $conn=mysqli_connect('localhost','root','','practice');
		  $table=mysqli_query($conn,'SELECT * FROM `try`');
		  while($row=mysqli_fetch_array($table))
		  {
			  $id=$row['id'];
			  $date=$row['fes'];
			  $salary=$row['bus'];
			  $recurrent=$row['snacks'];
			  $repairs_maint=$row['other'];
			  $creditors=$row['total'];	 
		  ?>
		  <tr>
			<td class="sno"><?php echo $id ?></td>
			<td class="mark"><?php echo $fes ?></td>
			<td class="mark"><?php echo $bus ?></td>
			<td class="mark"><?php echo $snacks?></td>
			<td class="mark"><?php echo $other?></td>
			<td class="mark"><?php echo $total?></td>
			
		  <?php } ?>
		  
		  <?php 
		  $add=mysqli_query($conn,'SELECT SUM(fes),SUM(bus),SUM(snacks),SUM(other) ,SUM(total) FROM  `try`');
		  while($row1=mysqli_fetch_array($add))
		  {
			$mark=$row1['SUM(fes)'];
			$mark1=$row1['SUM(bus)'];
			$mark3=$row1['SUM(snacks)'];	
			$mark4=$row1['SUM(other)'];
			$mark5=$row1['SUM(total)'];
		 ?>
		 
		  <tr>
		  <tr></tr>
		  <th>Total  =</th>
			<td><?php echo $mark ?></td>
			<td><?php echo $mark1 ?></td>
			<td><?php echo $mark3 ?></td>
			<td><?php echo $mark4 ?></td>
			<td><?php echo $mark5 ?></td>
			
		  <?php } ?>
		  
		</table>







Please i will appreciate your own code in html,php and sql thanks</pre

推荐答案




这篇关于如何对表的行和列求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 08:42