더하기 빼기가 이렇게 어려울 줄이야,,,,
본문
기존스킨을 활용해서 약간 변경하려는데 ...
wr_8의 월별 합산 및 총계는 잘나옵니다.
그런데 wr_255도 월별 합산을 추가하려는데 잘 안되네요,,,
for문 안에 뭔가를 집어넣어줘야 할거 같은데...
도와주세요,,,
$g5['title'] = '월별 실적';
include_once('./member_count.sub.php');
$colspan = 4;
$max = 0;
$sum_count = 0;
$sql = " select SUBSTRING(wr_datetime,1,7) as vs_month, sum(wr_8) as total, sum(wr_255) as refund
from g5_write_test
where date(wr_datetime) between '{$fr_date}' and '{$to_date}'
group by vs_month
order by vs_month desc";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$arr[$row['vs_month']] = $row['total'];
if ($row['total'] > $max) $max = $row['total'];
$sum_count += $row['total'];
}
?>
<div class="tbl_head01 tbl_wrap">
<table>
<caption><?php echo $g5['title']; ?> 목록</caption>
<thead>
<tr>
<th scope="col">년-월</th>
<th scope="col">그래프</th>
<th scope="col">총입금</th>
<th scope="col">총환불</th>
<th scope="col">총실적</th>
<th scope="col">비율(%)</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2">합계</td>
<td><strong><?php echo number_format($sum_count) ?></strong></td>
<td><?php echo number_format($sum_refund) ?></td>
<td></td>
</td></td>
<td>100%</td>
</tr>
</tfoot>
<tbody>
<?php
$i = 0;
$k = 0;
$save_count = -1;
$tot_count = 0;
if (count($arr)) {
foreach ($arr as $key=>$value) {
$count = $value;
$rate = ($count / $sum_count * 100);
$s_rate = number_format($rate, 1);
$bg = 'bg'.($i%2);
?>
<tr class="<?php echo $bg; ?>">
<td class="td_category"><a href="./visit_date.php?fr_date=<?php echo $key ?>-01&to_date=<?php echo $key ?>-31"><?php echo $key ?></a></td>
<td>
<div class="visit_bar">
<span style="width:<?php echo $s_rate ?>%"></span>
</div>
</td>
<td class="td_numbig"><?php echo number_format($value) ?></td>
<td class="td_numbig"></td>
<td class="td_numbig"></td>
답변 5
refund가 월별로 표시는 안됩니다. 라는 말씀이
각각 월별로 안나타나는 증상을 말씀하시는건가요??
혹시 각각 월별의 표시를 $sum_refund 로찍으신건 아닐까요??
각각의 월별의 표시는 $row[refund] 로 찍으시면 될것 같은데요..
아니라면 $arr[$row['vs_month']] = $row['total']; 값처럼
$arr[$row['vs_month2']] = $row['refund']; 라는 값을 넣어주셔서 사용하셔도 될것같네요
if ($row['total'] > $max) $max = $row['total'];
$sum_count += $row['total'];
이부분 아래에
$sum_refund += $row['refund'];
이렇게 추가하면 될 것 같은데요?
wr_8과 wr_255의 DB table 데이터 타입을 우선적으로 비교해 보시고요..
우선 합산의 결과가 어떻게 나와서 이런 식으로 원한다 라고 써주시면 답변하는데 더욱 도움이 될것 같네요.
년-월 | 그래프 | 총입금 | 총환불 | 총실적 | 비율(%) |
---|---|---|---|---|---|
합계 | 221,427 | 0 | 100% | ||
2019-04 | 20,303 | 9.2 | |||
2019-03 | 59,622 | 26.9 | |||
2019-02 | 71,399 | 32.2 | |||
2019-01 | 70,102 | 31.7 |
위와 같이 입금 wr_8은 잘 나옵니다. 환불 wr_255도 뽑고 그것을 +-한 실적을 뽑으려는 겁니다,
sum(wr_8) as total 에 대해서는 하단 for 문에 $sum_count += $row['total'];해서 합산을 하라고 명령이 되어있는데...sum(wr_255) as refound 에 대해서는 합산을 하라는 명령이 없습니다.
해서 해당 부분을 추가 하시면 될것 같고 위에 댓글을 달아주신
뽁스 님의 의견대로 $sum_refund += $row['refund'];것을추가 하시면 될거라 생각됩니다.
$sum_count += $row['total']; 밑에
$sum_refund += $row['refund']; 을 추가 하시면 될것으로 보여집니다.
머시기거시기님이 작성하신 원본에서 <?php echo number_format($sum_refund) ?>이런 내용이 존재 하나 저 $sum_refund에 대해 어느곳에도 선언된 곳이 없어서 그런게 아닐까 조심스레 생각해봅니다.
제가 머시기 거시기 님의 문의 내용을 제대로 이해했는지 모르겠네요..아니라면 죄송합니다.