채택완료

sql에서 동일값 확인 후 내용 뽑기

Copy
<?
        $write_table = $g5['write_prefix'] . $bo_table;
        $sum_count = "0";
        $sql = "
            select a.mb_id, b.mb_name, count(*) as cnt , sum(a.wr_31) as tot        
              from {$write_table} a
                       left outer join {$g5['member_table']} b on a.mb_id = b.mb_id 
             where wr_29 between '{$stx1}' and '{$stx2}'
             group by a.mb_id, b.mb_name ORDER BY tot DESC
        ";
        $result = sql_query($sql);
        while ($row = sql_fetch_array($result)) {
        $sum_count ++
        ?>

        <tr>
            <td class="td_c"><?php echo $sum_count ?>위</td>
            <td class="td_c"><?php echo $row['mb_name'] ?></td>
            <td class="td_c"><?php echo $row['cnt'] ?> 명</td>
            <td class="td_r"><?php echo number_format($row['tot']) ?>원</td>
        <?php } ?>

 

wr_29의 날짜내에 wr_31의 합계금액을 계산해서 순위를 정하는 소스입니다...

 

여기서 wr_30의 내용을 함께 뿌려주고 싶은데 어떻게 해야 하나요?

 

wr_30의 내용은 

[wr_30] => 스킨|단품|블랙|화이트

이런식으로 들어가 있습니다.

wr_31은 wr_30을 모두 더한 값입니다.

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

<?
$write_table = $g5['write_prefix'] . $bo_table;
$sum_count = "0";
$sql = "
    select a.mb_id, b.mb_name, a.wr_30, count(*) as cnt , sum(a.wr_31) as tot        
      from {$write_table} a
               left outer join {$g5['member_table']} b on a.mb_id = b.mb_id 
     where wr_29 between '{$stx1}' and '{$stx2}'
     group by a.mb_id, b.mb_name ORDER BY tot DESC
";
$result = sql_query($sql);
while ($row = sql_fetch_array($result)) {
$sum_count ++
?>
<tr>
    <td class="td_c"><?php echo $sum_count ?>위</td>
    <td class="td_c"><?php echo $row['mb_name'] ?></td>
    <td class="td_c"><?php echo $row['cnt'] ?> 명</td>
    <td class="td_r"><?php echo number_format($row['tot']) ?>원</td>
    <td class="td_r"><?php echo $row['wr_30'] ?></td>
<?php } ?>
 

db에서 읽어 올 필드를 지정하세요.

답변에 대한 댓글 1개

<?php echo $row['wr_30'] ?>했더니

스킨|단품|블랙|화이트

이렇게 나옵니다.

이걸 한개씩 나눌려면 어떻게 해야 하나요?

답변을 작성하려면 로그인이 필요합니다.