주문 주적값의 회원별 순위 매기기
본문
아래와 같이 회원별로 기간별 영카트에서 주문 누적을 구하고 있습니다.
여기서 구한 누적값 <?php echo $aa?> 에 대한 순위를 구해서 출력하고 싶습니다.
누적값이라 쿼리문에서의 정렬은 안될거 같고,
어떻게 해야할지 감이 안잡히네요. 도와주세요~
for ($i=0; $row=sql_fetch_array($result); $i++) {
?>
<tr class="<?php echo $bg; ?>">
<td style="text-align:center; padding:5px 0px; width:20%"><?php echo $row['mb_id']; ?><br><?php echo $row['mb_name']; ?></td>
<td style="text-align:center;">
<?php
$sql01 = " select * from {$g5['g5_shop_cart_table']} where left(od_id, 8) > '{$start_date}' and left(od_id, 8) < '{$end_date}' and ct_status in ('입금', '준비', '배송', '완료') and ct_recommend = '{$member['mb_id']}' and mb_id = '{$row['mb_id']}' order by ct_id asc ";
$result01 = sql_query($sql01);
$aa = 0;
for ($m=0; $row01=sql_fetch_array($result01); $m++) {
$result_item01 = sql_fetch( " select * from g5_shop_item where it_id = '{$row01['it_id']}' and it_10 = 'Y' " );
if($result_item01['it_id']){
$aa = $aa + $row01['ct_qty'];
}
} ?>
<?php echo $aa?>
</td>
</tr>
<?php
}
답변 1
select count(*) as cnt from {$g5['g5_shop_cart_table']} a, {$g5['g5_shop_item_table']} b where left(a.od_id, 8) > '{$start_date}' and left(a.od_id, 8) < '{$end_date}' and a.ct_status in ('입금', '준비', '배송', '완료') and a.ct_recommend = '{$member['mb_id']}' and a.mb_id = '{$row['mb_id']}' and b.it_id = a.it_id and b.it_10 = 'Y'
이런식의 쿼리문으로 for문이 아닌 바로 가져오도록 처리해 주셔야 할듯 합니다.
cnt값을 가져오면 해결되실듯 합니다.
답변을 작성하시기 전에 로그인 해주세요.