콤마 값을 제외하고 전달하려고 합니다.

콤마 값을 제외하고 전달하려고 합니다.

QA

콤마 값을 제외하고 전달하려고 합니다.

본문

안녕하세요 항상 도움 받고 있습니다. 숫자를 적어서 submit 을 할 때 숫자가 적힐 때는 콤마가 적용되게 하고 싶지만 post 로 전달 할 때는 콤마 값을 없애고 싶습니다. 어떻게 해야 하나요?

코드는 아래와 같습니다. 
 

<tr>

                  <th>

                    <label class="control-label" for="">매매가 가격범위</label>

                  </th>

                  <td>

                    <input type="text" name="trading_price_from" id="trading_price_from" class=" form-control box_style" placeholder="" value="<?php echo $trading_price_from; ?>">

                    <span>~</span>

                    <input type="text" name="trading_price_to" id="trading_price_to" class=" form-control box_style" placeholder="" value="<?php echo $trading_price_to; ?>">

                    <span>원</span>

                  </td>

                </tr>

 

                <script>

                  // 천 단위 콤마를 추가하는 함수

                  function addCommas(input) {

                    return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

                  }

 

                  // 값이 입력될 때마다 천 단위 콤마 추가

                  document.getElementById('trading_price_from').addEventListener('input', function () {

                    this.value = addCommas(this.value.replace(/,/g, ''));

                  });

 

                  document.getElementById('trading_price_to').addEventListener('input', function () {

                    this.value = addCommas(this.value.replace(/,/g, ''));

                  });

                </script>

bbs/list.php

 

      // 콤마를 제거하여 정수로 변환

$trading_price_from = isset($_POST['trading_price_from']) ? (int)str_replace(',', '', $_POST['trading_price_from']) : null;

$trading_price_to = isset($_POST['trading_price_to']) ? (int)str_replace(',', '', $_POST['trading_price_to']) : null;

 

// 매매가 가격범위 검색 조건 추가

if ($trading_price_from !== null && $trading_price_to !== null) {

    $sql_search .= "AND (CONVERT(REPLACE(trading_price, ',', ''), SIGNED) BETWEEN '{$trading_price_from}' AND '{$trading_price_to}') ";

}

 

항상 감사합니다. 

이 질문에 댓글 쓰기 :

답변 2

답변을 작성하시기 전에 로그인 해주세요.
전체 125,873 | RSS
QA 내용 검색

회원로그인

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