print_item_options() 함수에서 $str값 두개받고싶습니다.

print_item_options() 함수에서 $str값 두개받고싶습니다.

QA

print_item_options() 함수에서 $str값 두개받고싶습니다.

본문

print_item_options() 함수에서 $str값 두개받고싶습니다.

$str 뿐만아니라 $str2도 만들어서 리턴받고싶습니다.

제가 작성한 방식의 문법으로는 되지않아서요.자문를 구합니다.

oerderform.sub.php 에서 $it_options = print_item_options($row['it_id'], $s_cart_id); 이렇게해서

$str을 호출하는데요. $str2를 호출해서 사용하려면 어떤식으로 해야가능한가요?

printitem_options2($it_id, $cart_id) 함수를 똑같이 만들면 되긴하는데요.비효율적인것같에서요.

알려주시면 감사하겠습니다.

 


function print_item_options($it_id, $cart_id)
{
    global $g5;
    $sql = " select ct_option, ct_qty, io_price
                from {$g5['g5_shop_cart_table']} where it_id = '$it_id' and od_id = '$cart_id' order by io_type asc, ct_id asc ";
    $result = sql_query($sql);
    $str = '';
    $str2 = '';
    for($i=0; $row=sql_fetch_array($result); $i++) {
        if($i == 0)
            $str .= '<ul>'.PHP_EOL;
        $price_plus = '';
        if($row['io_price'] >= 0)
            $price_plus = '+';
        $str .= '<li>'.get_text($row['ct_option']).' '.$row['ct_qty'].'개 ('.$price_plus.display_price($row['io_price']).')</li>'.PHP_EOL;
###############추가하려고하는부분############################
        $str2 .= '<li>'.$price_plus.display_price($row['io_price']).')</li>'.PHP_EOL;
##########################################################
    }
    if($i > 0)
        $str .= '</ul>';
        $str2 .= '</ul>';
    return $str;
    return $str2;
}

이 질문에 댓글 쓰기 :

답변 2

배열을 사용해서 다음과 같이 해 볼 수 있을 것 같습니다


function print_item_options($it_id, $cart_id)
{
    global $g5;
    $sql = " select ct_option, ct_qty, io_price
                from {$g5['g5_shop_cart_table']} where it_id = '$it_id' and od_id = '$cart_id' order by io_type asc, ct_id asc ";
    $result = sql_query($sql);
    $str = '';
    $str2 = '';
    for($i=0; $row=sql_fetch_array($result); $i++) {
        if($i == 0) {
            $str .= '<ul>'.PHP_EOL;
            $str2 .= '<ul>'.PHP_EOL;
        }
        $price_plus = '';
        if($row['io_price'] >= 0)
            $price_plus = '+';
        $str .= '<li>'.get_text($row['ct_option']).' '.$row['ct_qty'].'개 ('.$price_plus.display_price($row['io_price']).')</li>'.PHP_EOL;
        $str2 .= '<li>'.$price_plus.display_price($row['io_price']).'</li>'.PHP_EOL;
    }
    if($i > 0) {
        $str .= '</ul>';
        $str2 .= '</ul>';
    }
    return array($str, $str2);
}
// 호출하는 곳에서는 배열의 각 요소를 각각의 변수에 저장
list($it_options, $it_options2) = print_item_options($row['it_id'], $s_cart_id);

리턴값을 배열로 만드셔서 받는 곳에서 처리하시면 되지 않을까요?

$data[] = $str;

$data[] = $str2;

return $data; 로 배열 넘겨주고 받는곳에서 배열로 처리하면 될거 같습니다.

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

회원로그인

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