숫합 합계 방법 문의드립니다.
잘부탁합니닿
5년 전
조회 3,412
안녕하세요 문의좀드리겠습니다.
이부분의 숫자를
페이지 아무곳에나 숫자 합계를 하는 방법을 알 수 있을까요`?
</p>
<p> </p>
<p> <?php
$chk_cnt = 0;
for($i=0; $row=sql_fetch_array($result); $i++) {
// 상품이미지
$image = get_it_image($row['it_id'], 50, 50);</p>
<p> // 상품의 옵션정보
$sql = " select ct_id, it_id, ct_price, ct_point, ct_qty, ct_option, ct_status, cp_price, ct_stock_use, ct_point_use, ct_send_cost, io_type, io_price
from {$g5['g5_shop_cart_table']}
where od_id = '{$od['od_id']}'
and it_id = '{$row['it_id']}'
order by io_type asc, ct_id asc ";
$res = sql_query($sql);
$rowspan = sql_num_rows($res);</p>
<p> // 합계금액 계산
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
SUM(ct_qty) as qty
from {$g5['g5_shop_cart_table']}
where it_id = '{$row['it_id']}'
and od_id = '{$od['od_id']}' ";
$sum = sql_fetch($sql);</p>
<p> // 배송비
switch($row['ct_send_cost'])
{
case 1:
$ct_send_cost = '착불';
break;
case 2:
$ct_send_cost = '무료';
break;
default:
$ct_send_cost = '선불';
break;
}</p>
<p> // 조건부무료
if($row['it_sc_type'] == 2) {
$sendcost = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $od['od_id']);</p>
<p> if($sendcost == 0)
$ct_send_cost = '무료';
}</p>
<p> for($k=0; $opt=sql_fetch_array($res); $k++) {
if($opt['io_type'])
$opt_price = $opt['io_price'];
else
$opt_price = $opt['ct_price'] + $opt['io_price'];</p>
<p> // 소계
$ct_price['stotal'] = $opt_price * $opt['ct_qty'];
$ct_point['stotal'] = $opt['ct_point'] * $opt['ct_qty'];
?>
<tr style=" height: 100px;">
<?php if($k == 0) { ?>
<td rowspan="<?php echo $rowspan; ?>" class="td_chk" >
<?php echo $i+1; ?> </td>
<td rowspan="<?php echo $rowspan; ?>" class="td_left">
<a href="./itemform.php?w=u&it_id=<?php echo $row['it_id']; ?>"><?php echo $image; ?> <?php echo stripslashes($row['it_name']); ?></a>
<?php if($od['od_tax_flag'] && $row['ct_notax']) echo '[비과세상품]'; ?>
</td>
<?php } ?>
<td><?php $it= sql_fetch("select it_maker , it_basic from {$g5['g5_shop_item_table']} where it_id = '{$row['it_id']}' "); ?><?php echo $it['it_maker']; ?> </td>
<td class="td_left">
<?php $it= sql_fetch("select it_origin , it_basic from {$g5['g5_shop_item_table']} where it_id = '{$row['it_id']}' "); ?> <?php echo $it['it_origin']; ?>
</td>
<td class="td_num">
<label for="ct_qty_<?php echo $chk_cnt; ?>" class="sound_only" value="<?php echo $opt['ct_qty']; ?>"> 수량</label>
<span class="quantity"><?php echo $opt['ct_qty']; ?></span>
</td>
<td class="td_num_right "><input type="text" name="opt_price" class="price" value="<?php echo number_format($opt_price); ?>" onKeyup="inputNumberAutoComma(this);"> </td>
<td class="td_num_right"><span class="calc_price"><?php echo number_format($ct_price['stotal']); ?></span></td>
</tr></p>
<p>
<?php
$chk_cnt++;
}
?>
<?php
}
?></p>
<p> </p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
5년 전
이건 출력할때 사용하시는 방버이구요
</p>
<p><?php </p>
<p>$tot_ct_price = 0;</p>
<p>//처음에 이걸 넣으시고</p>
<p> </p>
<p>$tot_ct_price += $ct_price['stotal'];</p>
<p>//와 같이 필요한 자리에서 합계를 만드실 내용을 더하시고</p>
<p> </p>
<p> </p>
<p>//출력은</p>
<p>echo number_format($tot_ct_price);</p>
<p>//로 출력하시면됩니다.</p>
<p> </p>
<p> </p>
<p>?></p>
<p>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 4개
�
잘부탁합니닿
5년 전
�
잘부탁합니닿
5년 전
이부분은 해당관련 스크립트 부분입니다.
<script>
// 반복되는 부분 말고, 한번만 출력되면 OKAY
$('.price').on('keyup', function() {
var quantity = parseInt($(this).closest('tr').find('.quantity').text().replace(/[^\d]+/g, '')) | 0;
var price = parseInt($(this).val().replace(/[^\d]+/g, '')) | 0;
$(this).closest('tr').find('.calc_price').text(quantity*price);
$(this).closest('tr').find('.calc_price').text(new Intl.NumberFormat().format(quantity*price));
});
function inputNumberAutoComma(obj) {
// 콤마( , )의 경우도 문자로 인식되기때문에 콤마를 따로 제거한다.
var deleteComma = obj.value.replace(/\,/g, "");
// 콤마( , )를 제외하고 문자가 입력되었는지를 확인한다.
if(isFinite(deleteComma) == false) {
alert("문자는 입력하실 수 없습니다.");
obj.value = "";
return false;
}
// 기존에 들어가있던 콤마( , )를 제거한 이 후의 입력값에 다시 콤마( , )를 삽입한다.
obj.value = inputNumberWithComma(inputNumberRemoveComma(obj.value));
}
// 천단위 이상의 숫자에 콤마( , )를 삽입하는 함수
function inputNumberWithComma(str) {
str = String(str);
return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, "$1,");
}
// 콤마( , )가 들어간 값에 콤마를 제거하는 함수
function inputNumberRemoveComma(str) {
str = String(str);
return str.replace(/[^\d]+/g, "");
}
</script>
<script>
// 반복되는 부분 말고, 한번만 출력되면 OKAY
$('.price').on('keyup', function() {
var quantity = parseInt($(this).closest('tr').find('.quantity').text().replace(/[^\d]+/g, '')) | 0;
var price = parseInt($(this).val().replace(/[^\d]+/g, '')) | 0;
$(this).closest('tr').find('.calc_price').text(quantity*price);
$(this).closest('tr').find('.calc_price').text(new Intl.NumberFormat().format(quantity*price));
});
function inputNumberAutoComma(obj) {
// 콤마( , )의 경우도 문자로 인식되기때문에 콤마를 따로 제거한다.
var deleteComma = obj.value.replace(/\,/g, "");
// 콤마( , )를 제외하고 문자가 입력되었는지를 확인한다.
if(isFinite(deleteComma) == false) {
alert("문자는 입력하실 수 없습니다.");
obj.value = "";
return false;
}
// 기존에 들어가있던 콤마( , )를 제거한 이 후의 입력값에 다시 콤마( , )를 삽입한다.
obj.value = inputNumberWithComma(inputNumberRemoveComma(obj.value));
}
// 천단위 이상의 숫자에 콤마( , )를 삽입하는 함수
function inputNumberWithComma(str) {
str = String(str);
return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, "$1,");
}
// 콤마( , )가 들어간 값에 콤마를 제거하는 함수
function inputNumberRemoveComma(str) {
str = String(str);
return str.replace(/[^\d]+/g, "");
}
</script>
�
플래토
5년 전
@잘부탁합니닿
제가 적어드린건 실제 사용하라고 적어드린게아니라.
개념적인 형태의 변수사용방법을 알려드린것입니다.
질문하신 변수에 대해서도
지금 상단/하단에 적으신 내용과 일치하는 내용이 없습니다.
더하실것을 별도의 변수를 만들어서 사용하시라고 적은것입니다.
for문 안에서 더하실 내용을 더하시고
for문 밖에서 출력을 하시면 됩니다.
제가 적어드린건 실제 사용하라고 적어드린게아니라.
개념적인 형태의 변수사용방법을 알려드린것입니다.
질문하신 변수에 대해서도
지금 상단/하단에 적으신 내용과 일치하는 내용이 없습니다.
더하실것을 별도의 변수를 만들어서 사용하시라고 적은것입니다.
for문 안에서 더하실 내용을 더하시고
for문 밖에서 출력을 하시면 됩니다.
�
잘부탁합니닿
5년 전
아..넵 ㅠㅠ 봐도 모르는까막눈이라... 우선 답변 주셔서 감사합니다..
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
<?php
$chk_cnt = 0;
for($i=0; $row=sql_fetch_array($result); $i++) {
// 상품이미지
$image = get_it_image($row['it_id'], 50, 50);
// 상품의 옵션정보
$sql = " select ct_id, it_id, ct_price, ct_point, ct_qty, ct_option, ct_status, cp_price, ct_stock_use, ct_point_use, ct_send_cost, io_type, io_price
from {$g5['g5_shop_cart_table']}
where od_id = '{$od['od_id']}'
and it_id = '{$row['it_id']}'
order by io_type asc, ct_id asc ";
$res = sql_query($sql);
$rowspan = sql_num_rows($res);
// 합계금액 계산
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
SUM(ct_qty) as qty
from {$g5['g5_shop_cart_table']}
where it_id = '{$row['it_id']}'
and od_id = '{$od['od_id']}' ";
$sum = sql_fetch($sql);
// 배송비
switch($row['ct_send_cost'])
{
case 1:
$ct_send_cost = '착불';
break;
case 2:
$ct_send_cost = '무료';
break;
default:
$ct_send_cost = '선불';
break;
}
// 조건부무료
if($row['it_sc_type'] == 2) {
$sendcost = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $od['od_id']);
if($sendcost == 0)
$ct_send_cost = '무료';
}
for($k=0; $opt=sql_fetch_array($res); $k++) {
if($opt['io_type'])
$opt_price = $opt['io_price'];
else
$opt_price = $opt['ct_price'] + $opt['io_price'];
// 소계
$ct_price['stotal'] = $opt_price * $opt['ct_qty'];
$ct_point['stotal'] = $opt['ct_point'] * $opt['ct_qty'];
?>
<tr style=" height: 100px;">
<?php if($k == 0) { ?>
<td rowspan="<?php echo $rowspan; ?>" class="td_chk" >
<?php echo $i+1; ?> </td>
<td rowspan="<?php echo $rowspan; ?>" class="td_left">
<a href="./itemform.php?w=u&it_id=<?php echo $row['it_id']; ?>"><?php echo $image; ?> <?php echo stripslashes($row['it_name']); ?></a>
<?php if($od['od_tax_flag'] && $row['ct_notax']) echo '[비과세상품]'; ?>
</td>
<?php } ?>
<td><?php $it= sql_fetch("select it_maker , it_basic from {$g5['g5_shop_item_table']} where it_id = '{$row['it_id']}' "); ?><?php echo $it['it_maker']; ?> </td>
<td class="td_left">
<?php $it= sql_fetch("select it_origin , it_basic from {$g5['g5_shop_item_table']} where it_id = '{$row['it_id']}' "); ?> <?php echo $it['it_origin']; ?>
</td>
<td class="td_num">
<label for="ct_qty_<?php echo $chk_cnt; ?>" class="sound_only" value="<?php echo $opt['ct_qty']; ?>"> 수량</label>
<span class="quantity"><?php echo $opt['ct_qty']; ?></span>
</td>
<td class="td_num_right "><input type="text" name="opt_price" class="price" value="<?php echo number_format($opt_price); ?>" onKeyup="inputNumberAutoComma(this);"> </td>
<td class="td_num_right"><span class="calc_price"><?php echo number_format($ct_price['stotal']); ?></span></td>
</tr>
<?php
$chk_cnt++;
}
?>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php echo $pg_anchor; ?>
<?php echo number_format($ct_price['stotal']); ?>
<?php
$tot_ct_price = 0;
//처음에 이걸 넣으시고
$tot_ct_price += $ct_price['stotal'];
//와 같이 필요한 자리에서 합계를 만드실 내용을 더하시고
//출력은
echo number_format($tot_ct_price);
//로 출력하시면됩니다.
?>