더하기 빼기가 이렇게 어려울 줄이야,,,,

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
더하기 빼기가 이렇게 어려울 줄이야,,,,

QA

더하기 빼기가 이렇게 어려울 줄이야,,,,

본문

기존스킨을 활용해서 약간 변경하려는데 ...

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'];

 

이렇게 추가하면 될 것 같은데요?

 

$arr[$row['vs_month']] = $row['total'];

이 부분에서 월별 총입금을 배열로 집어넣고



if (count($arr)) {
        foreach ($arr as $key=>$value) {

여기서 해당 배열의 값이 있으면 foreach 로 배열값 길이만큼 반복문을 돌립니다.



<td class="td_numbig"><?php echo number_format($value) ?></td>

이 부분의 $value 가 배열($arr)에 들어가 있는 값들을 표시해주는거죠.


$arr 배열에 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에 대해 어느곳에도 선언된 곳이 없어서 그런게 아닐까 조심스레 생각해봅니다.

 

제가 머시기 거시기 님의 문의 내용을 제대로 이해했는지 모르겠네요..아니라면 죄송합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색
  • 개별 목록 구성 제목 답변작성자조회작성일
  • 질문이 없습니다.

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT