1.计算收入或支出表的金额总和
<?php //sum的function是用来记录支出/收入的金额总数。 // 现在遇到的问题是,如何将计算 收入表-支出表的差。 include 'conn.php'; function sum($name,$table_name){ // 进行数据筛选 $sql = "SELECT * FROM {$table_name} "; $query = mysql_query($sql); $list = array(); $sum1 = 0; while($res = mysql_fetch_array($query)) { $list[]=$res; $sum1 += $res['money']; } //检测录入的表名,如果是payout,显示负数 if($table_name == 'payout'){ echo '<h3 align = "center" >'.$name.":"." - ".$sum1."</h3>"; } else{ echo '<h3 align = "center" >'.$name.":".$sum1."</h3>"; } } // $sum2 = $sum('收入表:','income'); // $sum1 = $sum('收入表:','payout'); ?>
2.收入列表
<?php session_start(); error_reporting(0); include 'conn.php'; include 'header.php'; include 'sum.php'; if(!$_SESSION['user']) header('location:index.php'); //分页逻辑 $length = 5; $pagenum=$_GET['page']?$_GET['page']:1; $offset = ($pagenum-1) * $length; $sql = "SELECT * FROM income order by id asc limit {$offset},{$length}"; $query = mysql_query($sql); //输出表格 echo '<table width="80%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c9c9c9" align="center"> <tr> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">项目</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">摘要</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">金额(元)</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">签订合同</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">提成</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">日期</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">负责人</span></strong></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE1">操作</span></strong></div></td> </tr>'; echo "<h3 align='center'>收入明细表</h3>"; while($res = mysql_fetch_array($query)) { ?> <html> <meta http-equiv='Content-Type' content='text/html' charset='UTF-8' > <head> <title></title> </head> <body> <form action="income_action.php" method="post"> <tr> <td height="22" bgcolor="#FFFFFF"><div align="center"><?php echo $res['project']; ?></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><span class="STYLE3"><?php echo $res['abs']; ?></span></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><span class="STYLE3"><?php echo $res['money']; ?></span></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center"><span class="STYLE3"><?php echo $res['whether']; ?> </span></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['commi']; ?></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['dates']; ?></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['user']; ?></div></td> <td height="22" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><a href="income_edit.php?id=<?php echo $res['id'];?>">编辑</a> <a href="income_del.php?id=<?php echo $res['id'];?>">删除</a></div></td> </tr> </form> </body> </html> <?php } echo "</table>"; //获取上一页下一页 $prevpage = $pagenum-1; $nextpage = $pagenum+1; ?> <html> <meta http-equiv='Content-Type' content='text/html' charset='UTF-8' > <head> <title></title> </head> <body> <h3 align="center" ><a href="inlist.php?page=<?php echo $prevpage ?>">上一页</a> | <a href="inlist.php?page=<?php echo $nextpage ?>">下一页</a> </h3> </body> </html> <?php // 计算总价 echo $table =sum('收入表明细','income'); ?>
3.支出列表
<?php //读取payout表中的内容,并以表格形式显示 session_start(); error_reporting(0); include("conn.php"); include 'function.php'; include 'sum.php'; if(!$_SESSION['user']) header("location:login.php"); include("header.php"); echo '<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />'; //分页逻辑 $pagesize = 20; $pagenum = $_GET['page'] ? $_GET['page'] : 1; $offset = ($pagenum - 1) * $pagesize; $sql = "SELECT * FROM payout order by pid asc limit {$pagenum},{$pagesize} "; $query = mysql_query($sql); //表格开始 echo '<table width="80%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c9c9c9" align="center">'; echo '<tr> <td height="26" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE2">项目明细</span></strong></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE2">摘要</span></strong></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE2">金额</span></strong></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE2">日期</span></strong></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center"><strong><span class="STYLE2">经手人</span></strong></div></td> </tr>'; echo "<h3 align='center'>支出明细表</h3>"; //循环读取数据开始 while ( $res = mysql_fetch_array($query)) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>支出表填写</title> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .STYLE3 {color: #707070; font-size: 12px; } .STYLE5 {color: #707070; font-size: 14px; } body { margin-top: 0px; margin-bottom: 0px; } .STYLE7 {font-size: 12} --> </style> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <form action="payout_action.php" method="post" > <tr> <td> <tr> <td height="26" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['project']; ?> </div></td> <td height="26" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['abs']; ?></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['money']; ?></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center" class="STYLE5"><?php echo $res['dates']; ?></div></td> <td height="26" bgcolor="#FFFFFF"><div align="center" class="STYLE5"> <?php echo $res['user']; ?></div></td> </tr> <?php } echo "</table>"; //获取上一页下一页 $prevpage = $pagenum-1; $nextpage = $pagenum+1; ?> <h3 align="center" ><a href="paylist.php?page=<?php echo $prevpage ?>">上一页</a> | <a href="paylist.php?page=<?php echo $nextpage ?>">下一页</a> </h3> </form> </body> </html> <?php $sql = "SELECT * from payout"; $query = mysql_query($sql); //开始计算 echo $sum = sum("收入表","payout"); mysql_close(); ?>