2026, 새로운 도약을 시작합니다.

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) 함수를 똑같이 만들면 되긴하는데요.비효율적인것같에서요.

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

Copy


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 .= ''.PHP_EOL;

        $price_plus = '';

        if($row['io_price'] >= 0)

            $price_plus = '+';

        $str .= ''.get_text($row['ct_option']).' '.$row['ct_qty'].'개 ('.$price_plus.display_price($row['io_price']).')'.PHP_EOL;

###############추가하려고하는부분############################

        $str2 .= ''.$price_plus.display_price($row['io_price']).')'.PHP_EOL;

##########################################################

    }

    if($i > 0)

        $str .= '';

        $str2 .= '';

    return $str;

    return $str2;

}

답변 2개

채택된 답변
+20 포인트

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

Copy


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 .= ''.PHP_EOL;

            $str2 .= ''.PHP_EOL;

        }

        $price_plus = '';

        if($row['io_price'] >= 0)

            $price_plus = '+';

        $str .= ''.get_text($row['ct_option']).' '.$row['ct_qty'].'개 ('.$price_plus.display_price($row['io_price']).')'.PHP_EOL;

        $str2 .= ''.$price_plus.display_price($row['io_price']).''.PHP_EOL;

    }

    if($i > 0) {

        $str .= '';

        $str2 .= '';

    }

    return array($str, $str2);

}

// 호출하는 곳에서는 배열의 각 요소를 각각의 변수에 저장

list($it_options, $it_options2) = print_item_options($row['it_id'], $s_cart_id);
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

제가 순간 실수를 좀 했으나 배열처리로 성공하였습니다.
답변 정말감사합니다.

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

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

$data[] = $str;

$data[] = $str2;

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

로그인 후 평가할 수 있습니다

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

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

로그인
🐛 버그신고