急急急!在线求助!

WBOY
Release: 2016-06-23 14:26:41
Original
958 people have browsed it

有这么个需求。根据时间,来汇总各店相关数据。数据库里的数据,是一天传送两次。需要做一个累加

最终的效果表是下图显示



前面是上图列名,后者是数据库列对应名

网费收入==网费收入  
会员收入==会员收入  
商品收入==商品收入  
点卡收入==点卡收入 
合计==临时卡消费总额
网费单机==(网费收入+会员收入)/dmmc(表)里的对应店名机器数量列。
商品单机==商品收入/dmmc(表)里的对应店名机器数量列。
点卡单机==点卡收入/dmmc(表)里的对应店名机器数量列。
合计就是对应列相加
日均就是对应列相加之后/天数

以其中一个店面数据库表数据为例。下图



dmmc表截图




求代码!!


回复讨论(解决方案)

第二张图重新上传下。  以11.1号数据为准就可以

图片看不到,每日汇总的话可以用linux的定时任务和php命令行传递参数,总和不是select sum(字段)就行了么?

图片看不到,每日汇总的话可以用linux的定时任务和php命令行传递参数,总和不是select sum(字段)就行了么?

你好 能不能加您qq  请教你几个问题

$result=mysql_query("SELECT 日期,网费收入,会员收入,商品收入,点卡收入,网费收入+会员收入+商品收入+点卡收入 AS 合计 FROM ".$data." ",$link);

在sql中能把 每行前列的数读取出来,第五列算个求合,在mysql查询器能查出来,但是网页上却直接没有数据。如果去掉求这四列的值,就能出来 。。。 真郁闷了

你网页上取数据的时候取了合计字段了吗?还是只有前面5个字段?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>店面营业查询结果</title><style type="text/css"><!--.style2 {font-size: 14px}--></style></head><body><span class="style2"><?$top=$_POST["d_s"];$end=$_POST["d_e"];$data=$_POST["shujuku"];echo "$data.$end.$top";echo "您所查询的数据是:";echo "&nbsp$top";echo "到&nbsp";echo "$end&nbsp";echo "之间的全部数据&nbsp&nbsp&nbsp ";echo "\r<a href='javascript:onclick=history.go(-1)'>返回上页</a> ";     echo "<form action=\"searchdc.php\" method=\"post\">";              echo "<input name=\"top\" type=\"hidden\" value=\"$top\">";              echo "<input name=\"end\" type=\"hidden\" value=\"$end\">";			  echo "<input name=\"dmmc\" type=\"hidden\" value=\"$data\">";              echo "<input type=\"submit\" name=\"Submit\" value=\"导出Excel表\">";     echo "</form>"; 	$link=mysql_connect("192.168.3.221","root","myoa888");$今天 =date("Y-m-d");mysql_query("use klserver");  //mysql_select_db("ttserver");$result=mysql_query("SELECT 日期,网费收入,会员收入,商品收入,点卡收入,网费收入+会员收入+商品收入+点卡收入 AS 合计 FROM ".$data." ",$link);echo "<table border=1>\n";echo"<tr>\n";while($field=mysql_fetch_field($result)){   echo"<td>".$field->name."</td>\n"; 	 $str= $str.$field->name.",";	 	  }    //生成新的查询字段  $length=strlen($str);  $sumstr=substr($str, 0, $length-1);  echo $sumstr;  echo "</tr>\n"; mysql_free_result($result);$result=mysql_query("SELECT $sumstr FROM $data where 日期 between '$top' and '$end'" ,$link); while($row = mysql_fetch_row($result)) { 	    echo "<tr>\n";   for($i=0;$i<count($row);$i++){     echo "<td>".$row[$i]."</td>";   }   echo "</tr>\n";}echo "</table>\n";mysql_free_result($result);mysql_close($link);?></span></body></html>
Copy after login

你网页上取数据的时候取了合计字段了吗?还是只有前面5个字段?

我把代码贴出来了。我放到查询器的时候 能查出。

我在代码里,如果不做四列的求和。也能出中间四列分别的数,并且打印在网页表格里。问题是我一加上这四个数,就一个数据都没有了。所以我贴上代码了

你前四列??都已?查出各列的和了,在WEB?面上?示的?候,?什?不直接把?四列的值相加然後?示

都是中文字段,,,,?

while($field=mysql_fetch_field($result)){     echo"<td>".$field->name."</td>\n";      $str= $str.$field->name.",";       }//用mysql_fetch_row()试试 打印$field看看有没有数据
Copy after login
Copy after login

都是中文字段,,,,?

while($field=mysql_fetch_field($result)){     echo"<td>".$field->name."</td>\n";      $str= $str.$field->name.",";       }//用mysql_fetch_row()试试 打印$field看看有没有数据
Copy after login
Copy after login


直接页面都不出来了。

你这个看的头疼...
给个思路给你...先查数据变数组
再依据你的表格遍历数组做运算...

<?php$pageTitle = "Test Log Summary"; //定义页面标头include_once './global.php'; //链接全局配置//获取测试记录最后更新时间$query = $db->select("bp_testloglist", "testEndtime", "order by testEndtime desc limit 0,1");if ($row = $db->fetch_array($query)) {    $lastUpdateint = $row['0'] + 54000;}unset($query);unset($row);$lastUpdatedayint = strtotime(date("Y-m-d",$lastUpdateint)); //依据dell时间换成当天的开始时间int//依据测试记录最后时间变成abc时间$queryDateint = $lastUpdatedayint - 6* 24 * 60 * 60-54000;//获取最后2天的测试时间$queryDateint2 = $lastUpdatedayint - 24 * 60 * 60- 54000;$querDateabc2int = $queryDateint2+54000;//获得测试工站的Performance$query = $db->select("bp_testloglist", "testStation,testResult, testEndtime", "where testEndtime>=$queryDateint and testDatabase=0");while ($row = $db->fetch_array($query)) {    $stationSummary[dellToabcdayint($row['2'])][$row['0']][$row['1']] = $stationSummary[dellToabcdayint($row['2'])][$row['0']][$row['1']] + 1;}unset($query);unset($row);$m_Testhate = $m_Testhate + 24 * 60 * 60;//获取测试工站名称$query = $db->query("select a.testerFullname,a.testerID,a.testerType,b.stationNamelite,a.testerName,INET_NTOA(a.testerIP) from bp_tester as a left join bp_teststation as b on a.testerType = b. stationID where a.testerShow=1 order by a.testerType, testerFullname asc");while ($row = $db->fetch_array($query)) {    $testType[$row['2']] = $row['3'];    $testerHost[$row['1']] = array('testerHost' => $row[4], 'testerIP' => $row['5'], 'testerStation' => $row['3']);    $testerName[$row['1']] = $row['0'];    $i++;}unset($query);unset($row);$currentTime = date("Y-m-d H:i:s");include_once './include/system.top.php';include_once './include/system.menu.php';?><ul class="tabs left">    <li><a href="#tester">TESTER</a></li></ul><div id="tester" class="tab-content">    <h5>[ Test Station Performance ]_UPDATE: [ <FONT COLOR='RED'><?PHP ECHO $currentTime; ?></FONT> ]</h5>    <table class="sortable">        <thead>            <tr>                <th colspan="2" rowspan ="2" class="center">Tester / Date</th>                <?php                $a = $queryDateint + 54000;                $i = 0;                for ($a; $a <= $lastUpdateint; $a = $a + 24 * 60 * 60) {                    $testDate[$i] = $a;                    echo "<th colspan='4' class='center'>" . date("Y-m-d", $a) . "<br>" . date("l", $a) . "</th>";                    $i++;                }                unset($a);                ?>            </tr>            <tr>                <?php                for ($a = 0; $a < $i; $a++) {                    ?>                    <th class="center">T</th>                    <th class="center">P</th>                    <th class="center">F</th>                    <th class="center">A</th>                                        <?php                }                ?>            </tr>        </thead>        <tbody>             <?php            if (!empty($testerHost)) {                foreach ($testerHost as $key => $value1) {                    $testerID = $key;                    ?>                    <tr>                        <td title="<?php echo $value1['testerStation'] . "=>HOST NAME: " . $value1['testerHost']; ?>" ><?php echo $testerName[$key]; ?></td>                        <td><?php echo $value1['testerIP']; ?></td>                        <?php                        foreach ($testDate as $value) {                            @$totalPass[$value] > 0 ? @$totalPass[$value] : @$totalPass[$value] = 0;                            @$totalFail[$value] > 0 ? @$totalFail[$value] : @$totalFail[$value] = 0;                            @$totalAbort[$value] > 0 ? @$totalAbort[$value] : @$totalAbort[$value] = 0;                            @$totalTotal[$value] > 0 ? @$totalTotal[$value] : @$totalTotal[$value] = 0;                            if (arrayValue($stationSummary, $value)) {                                if (arrayValue($stationSummary[$value], $testerID)) {                                    $tPass = (int) arrayValue($stationSummary[$value][$testerID], '3');                                    $tFail = (int) arrayValue($stationSummary[$value][$testerID], '1');                                    $tAbort = (int) arrayValue($stationSummary[$value][$testerID], '2');                                    $tTotal = $tPass + $tFail + $tAbort;                                    $totalPass[$value] = $totalPass[$value] + $tPass;                                    $totalFail[$value] = $totalFail[$value] + $tFail;                                    $totalAbort[$value] = $totalAbort[$value] + $tAbort;                                    $totalTotal[$value] = $totalTotal[$value] + $tTotal;                                } else {                                    $tPass = 0;                                    $tFail = 0;                                    $tAbort = 0;                                    $tTotal = $tPass + $tFail + $tAbort;                                    $totalPass[$value] = $totalPass[$value] + $tPass;                                    $totalFail[$value] = $totalFail[$value] + $tFail;                                    $totalAbort[$value] = $totalAbort[$value] + $tAbort;                                    $totalTotal[$value] = $totalTotal[$value] + $tTotal;                                }                            } else {                                $tPass = 0;                                $tFail = 0;                                $tAbort = 0;                                $tTotal = $tPass + $tFail + $tAbort;                                $totalPass[$value] = $totalPass[$value] + $tPass;                                $totalFail[$value] = $totalFail[$value] + $tFail;                                $totalAbort[$value] = $totalAbort[$value] + $tAbort;                                $totalTotal[$value] = $totalTotal[$value] + $tTotal;                            }                            if ($tTotal <> 0) {                                echo "<td class='center'><a href='tldetail.php?testDate=" . $value. "&testStation=$testerID' >$tTotal</a></td>";                            } else {                                echo "<td></td>";                            }                            if ($tPass <> 0) {                                echo "<td class='center'><a href='tldetail.php?testDate=" . $value. "&testStation=$testerID&testResult=3' ><font color='green'>$tPass</font></a></td>";                            } else {                                echo "<td></td>";                            }                            if ($tFail <> 0) {                                echo "<td class='center'><a href='tldetail.php?testDate=" . $value. "&testStation=$testerID&testResult=1' ><font color='Red'>$tFail</font></a></td>";                            } else {                                echo "<td></td>";                            }                            if ($tAbort <> 0) {                                echo "<td class='center'><a href='tldetail.php?testDate=" . $value. "&testStation=$testerID&testResult=2' ><font color='orange'>$tAbort</font></a></td>";                            } else {                                echo "<td></td>";                            }                        }                        ?>                    </tr>                    <?php                }            }            ?>            <tr>                <th colspan ="2" class="center">Total</th>                <?php                foreach ($testDate as $value) {                    if ($totalTotal[$value] <> 0) {                        echo "<th class='center'><a href='tldetail.php?testDate=" . $value. "' >$totalTotal[$value]</a></th>";                    } else {                        echo "<th></th>";                    }                    if ($totalPass[$value] <> 0) {                        echo "<th class='center'><a href='tldetail.php?testDate=" . $value . "&testResult=3' ><font color='green'>$totalPass[$value]</font></a></th>";                    } else {                        echo "<th></th>";                    }                    if ($totalFail[$value] <> 0) {                        echo "<td class='center'><a href='tldetail.php?testDate=" . $value . "&testResult=1' ><font color='Red'>$totalFail[$value]</font></a></th>";                    } else {                        echo "<th></th>";                    }                    if ($totalAbort[$value] <> 0) {                        echo "<th class='center'><a href='tldetail.php?testDate=" . $value. "&testResult=2' ><font color='orange'>$totalAbort[$value]</font></a></th>";                    } else {                        echo "<th></th>";                    }                }                $totalTotal = NULL;                $totalPass = NULL;                $totalFail = NULL;                $totalAbort = NULL;                ?>            </tr>        </tbody>    </table></div><?php include_once './include/system.boot.php'; ?>
Copy after login


算出来就是这个样子

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template