테스트 사이트 - 개발 중인 베타 버전입니다

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

만도리 1년 전 조회 1,493

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

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

 

</p>

<p>function print_item_options($it_id, $cart_id)

{

    global $g5;</p>

<p>    $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);</p>

<p>    $str = '';</p>

<p>    $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;</p>

<p>###############추가하려고하는부분############################</p>

<p>        $str2 .= '<li>'.$price_plus.display_price($row['io_price']).')</li>'.PHP_EOL;</p>

<p>##########################################################

    }</p>

<p>    if($i > 0)

        $str .= '</ul>';</p>

<p>        $str2 .= '</ul>';</p>

<p>    return $str;</p>

<p>    return $str2;

}</p>

<p>

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

답변 2개

채택된 답변
+20 포인트

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

</p>

<p>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);

}</p>

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

list($it_options, $it_options2) = print_item_options($row['it_id'], $s_cart_id);

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

답변에 대한 댓글 1개

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

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

1년 전

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

$data[] = $str;

$data[] = $str2;

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

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

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

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

로그인