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

Invalid argument supplied for foreach() in 에러 채택완료

qoqofh 4년 전 조회 4,142

foreach($DATA['cart'] as $key=>$val) {
        $this_price = ($val['ct_price']+$val['io_price']) * $val['ct_qty'];
        $total_price += $this_price;

 

이 구문에서 

 

Warning: Invalid argument supplied for foreach() in /www_root/shop/cartprint.php on line 196

 

라는 메세지가 뜨는데 무슨 에러일까요 ㅠㅠ?

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

답변 4개

채택된 답변
+20 포인트
Big1
4년 전

php 버전과 영카트 버전이 어떻게 되지요? 

 

</p>

<p>    <?php

    $total_price = 0;

    $this_price = 0;</p>

<p>    if (isset($DATA['cart']) && is_array($DATA['cart'])) {

    foreach($DATA['cart'] as $key=>$val) {

        $this_price = ($val['ct_price']+$val['io_price']) * $val['ct_qty'];

        $total_price += $this_price;

        

    ?>

    <tr>

        <td class="td-body"><?php $val['io_id']?></td>

        <td class="td-body"><?php $val['it_name']?></td>

        <td class="td-body"><?php $DATA['opt'][$key]['io_misc01']?></td>

        <td class="td-body"><?php $DATA['opt'][$key]['io_misc02']?></td>

        <td class="td-body td-right"><?=number_format($val['ct_price']+$val['io_price'])?></td>

        <td class="td-body td-center"><?=number_format($val['ct_qty'])?></td>

        <td class="td-body td-right"><?=number_format($this_price)?></td>

    </tr>

        

    <?

    } # end of if 

    } # end foreach;

    ?></p>

<p>

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

답변에 대한 댓글 2개

q
qoqofh
4년 전
지금 제가 사용하고있는 버전은 php는 7.0영카트는 5.3으로 알고있습니다.
q
qoqofh
4년 전
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in /www_root/lib/common.lib.php on line 1692

이런에러도 뜨는 상태입니다 ㅠㅠ

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

Big1
4년 전

5.4.4.x 에서 해봤는데 오류는 없었어요. 

$TMP = array();

$TMP['it'] = array();
$DATA = array();
$DATA['cart'] = array();

미리 변수 초기화를 해둔 코드
이 코드로도 오류가 난다면 

lib/common.lib.php 업데이트를 해당 부분만이라도 해보시고요
(sql_ 로 시작하는 함수)

$array 변수는 (session: cartprint)

이런 식으로 되어야 정상적으로 출력될 것 같습니다.

</p>

<p>$array = array(

    'it_id' => array('1490690285','1490690301'),

    'ct_chk' => array('1','1')

);</p>

<p>

 

 

</p>

<p><?php

include_once('./_common.php');

include_once(G5_PATH.'/head.sub.php');</p>

<p>//print_r($_GET);

//print_r($_POST);

# 세션데이터에서 장바구니 전송값을 가져온다. ---------------------------------------------------

# [cart.php -> ajax.cartprint.php 세션저장한 값]

$tmp_data = get_session("cartprint");

if($tmp_data) {

    $array = unserialize($tmp_data);

}</p>

<p>

//print_r($array);

# 장바구니 데이터 검사 --------------------------------------------------------------------------

if(is_array($array) && is_array($array['it_id']) && is_array($array['ct_chk'])) {

    # 장바구니 전송됨

} else {

    # 장바구니 전송안됨

    echo "<h2>견적서를 출력할 제품이 없습니다.</h2>";

    include_once(G5_PATH.'/tail.sub.php');

    exit;

}</p>

<p># 장바구니 no 가공 ---------------------------------------------------------------------------

/* 장바구니 상품번호와 체크여부(ct_chk)를 비교하여 견적할 제품번호만 남긴다. */

$TMP = array();

$TMP['it'] = array();

$DATA = array();

$DATA['cart'] = array();

if (isset($array['it_id']) && is_array($array['it_id'])) {

foreach($array['it_id'] as $key=>$val) {

    if(isset($array['ct_chk'][$key]) && $array['ct_chk'][$key]=="1") {

        $TMP['it'][] = $val;

    } else {

        continue;

    }

}

}

//print_r($TMP['it']);

if(is_array($TMP['it']) && is_array($TMP['it'])) {

    # 견적할 제품이 있음

} else {

    # 견적할 제품이 없음

    echo "<h2>견적서를 출력할 제품이 없습니다.</h2>";

    include_once(G5_PATH.'/tail.sub.php');

    exit;

}</p>

<p># 장바구니 DB 가져오기 ---------------------------------------------------------------------------

$s_cart_id = get_session('ss_cart_id');

// $s_cart_id 로 현재 장바구니 자료 쿼리

$qry = " SELECT * FROM {$g5['g5_shop_cart_table']} WHERE od_id = '$s_cart_id' AND it_id IN ( ". implode(",", $TMP['it']) ." ) ORDER BY it_id ";

$res = sql_query($qry) or die(sql_error_info());

if(sql_num_rows($res)>0) {

    $idx = 0;

    while($row = sql_fetch_array($res)) {

        $DATA['cart'][$idx] = $row;

        # 옵션DB 가져오기

        $qry2 = " SELECT * FROM {$g5['g5_shop_item_option_table']} WHERE it_id = '{$row['it_id']}' AND io_id='{$row['io_id']}' AND io_type='0' ";

        $res2 = sql_query($qry2);

        if(sql_num_rows($res2)>0) {

            $DATA['opt'][$idx] = sql_fetch_array($res2);

        }

        $idx++;

    }

}

//print_r($DATA);</p>

<p># 출력화면 그리기      ---------------------------------------------------------------------------

?></p>

<p><style type="text/css">

.print-wrap { width:600px; box-sizing:border-box; margin:5px auto; }

/* 표제부 */

.table-info { border-collapse:collapse; width:100%; }

.table-info * { font-size: 12px;}

.table-info td { border:1px solid #09a4b6; height:20px; }

.table-info .td-row-6 { background:#06899f; color:#ffffff; text-align:center; }

.table-info .td-head { background:#67b9c2; text-align:center; color:#ffffff; }

/* 제품리스트 */

.table-list { border-collapse:collapse; width:100%; margin:20px 0 0 0; }

.table-list * { font-size:12px;}

.table-list td { border:1px solid #09a4b6; height:20px; }

.table-list .td-head { background:#67b9c2; text-align:center; color:#ffffff; }

.table-list .td-body { font-size:11px !important; }

/* 공통 */

.input-1 { width:174px; }

.td-right { text-align:right; }

.td-center { text-align:center; }

/* 기타 */

.div-help { margin:10px 0; color:#2861c8; }

.print-button { width:600px; margin:10px auto; text-align:right; }

.print-button button { padding:4px 10px; background:#2548a5; color:#ffffff; border:0; }

@media print {

    .print-button { display:none; }

}

</style>

<div class="print-wrap">

    <table class="table-info">

    <col width="20">

    <col width="60">

    <col width="180">

    <col width="20">

    <col width="60">

    <col width="">

    <col width="60">

    <col width="">

    <tr>

        <td class="td-row-6" rowspan="6">의
뢰
자</td>

        <td class="td-head">견적일</td>

        <td class="td-body"><input type="text" class="input-1" value="<?php echo date("Y-m-d")?>"></td>

        <td class="td-row-6" rowspan="6">공
급
자</td>

        <td class="td-head">등록번호</td>

        <td class="td-body" colspan="3"><?php echo $default['de_admin_company_saupja_no']?></td>

    </tr>

    <tr>

        <td class="td-head">업체명</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">회사명</td>

        <td class="td-body"><?php echo $default['de_admin_company_name']?></td>

        <td class="td-head">성명</td>

        <td class="td-body"><?php echo $default['de_admin_company_owner']?></td>

    </tr>

    <tr>

        <td class="td-head">담당자</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">주소</td>

        <td class="td-body" colspan="3"><?php echo $default['de_admin_company_addr']?></td>

    </tr>

    <tr>

        <td class="td-head">전화</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">업태</td>

        <td class="td-body"><?php echo $default['de_biztype_a']?></td>

        <td class="td-head">종목</td>

        <td class="td-body"><?php echo $default['de_biztype_b']?></td>

    </tr>

    <tr>

        <td class="td-head">팩스</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">전화</td>

        <td class="td-body"><?php echo $default['de_admin_company_tel']?></td>

        <td class="td-head">팩스</td>

        <td class="td-body"><?php echo $default['de_admin_company_fax']?></td>

    </tr>

    <tr>

        <td class="td-head">E-mail</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">담당자</td>

        <td class="td-body" colspan="3"></td>

    </tr>

    </table>

    <table class="table-list">

    <col width="80">

    <col width="80">

    <col width="80">

    <col width="">

    <col width="60">

    <col width="40">

    <col width="70">

    <tr>

        <td class="td-head">제품번호</td>

        <td class="td-head">제품명</td>

        <td class="td-head">형식번호</td>

        <td class="td-head">제품사양</td>

        <td class="td-head">단가</td>

        <td class="td-head">수량</td>

        <td class="td-head">가격</td>

    </tr>

    <?php

    $total_price = 0;

    $this_price = 0;               

    if (isset($DATA['cart']) && is_array($DATA['cart'])) {

    foreach($DATA['cart'] as $key=>$val) {

        $this_price = ($val['ct_price']+$val['io_price']) * $val['ct_qty'];

        $total_price += $this_price;

        

    ?>

    <tr>

        <td class="td-body"><?php echo $val['io_id']?></td>

        <td class="td-body"><?php echo $val['it_name']?></td>

        <td class="td-body"><?php echo $DATA['opt'][$key]['io_misc01']?></td>

        <td class="td-body"><?php echo $DATA['opt'][$key]['io_misc02']?></td>

        <td class="td-body td-right"><?php echo number_format($val['ct_price']+$val['io_price'])?></td>

        <td class="td-body td-center"><?php echo number_format($val['ct_qty'])?></td>

        <td class="td-body td-right"><?php echo number_format($this_price)?></td>

    </tr>

    <?php

    } # end foreach;

    } # end of if

    ?>

    <tr>

        <td class="td-body td-center" colspan="6"><strong>합계금액</strong></td>

        <td class="td-body td-right"><strong><?php echo number_format($total_price)?></strong></td>

    </tr></p>

<p>    </table>

    <div class="div-help">

        상기 견적내용은 환율에 따라 가격이 변동될 수 있으니 참고용으로만 활용하시기 바랍니다.


        (견적내용 및 입력사항은 서버로 전송되지 않습니다)


        자세한 견적상담을 원하시면 <?php echo $default['de_admin_company_tel']?>로 전화바랍니다.

    </div>

</div>

<div class="print-button">

    <button type="button" onClick="print();">인쇄</button>

    <button type="button" onClick="window.close();">닫기</button>

</div></p>

<p><?php

include_once(G5_PATH.'/tail.sub.php');</p>

<p>

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

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

끄끄
4년 전

</strong><?php

include_once('./_common.php');</p>

<p>include_once(G5_PATH.'/head.sub.php');</p>

<p>

print_r($_GET);

print_r($_POST);</p>

<p># 세션데이터에서 장바구니 전송값을 가져온다. ---------------------------------------------------

# [cart.php -> ajax.cartprint.php 세션저장한 값]

$tmp_data = get_session("cartprint");

if($tmp_data) {

    $array = unserialize($tmp_data);

}

//print_r($array);</p>

<p># 장바구니 데이터 검사 --------------------------------------------------------------------------

if(is_array($array) && is_array($array['it_id']) && is_array($array['ct_chk'])) {

    # 장바구니 전송됨

} else {

    # 장바구니 전송안됨

    echo "<h2>견적서를 출력할 제품이 없습니다.</h2>";

    include_once(G5_PATH.'/tail.sub.php');

    exit;

}</p>

<p>

# 장바구니 no 가공 ---------------------------------------------------------------------------</p>

<p>/* 장바구니 상품번호와 체크여부(ct_chk)를 비교하여 견적할 제품번호만 남긴다. */</p>

<p>if (isset($DATA['cart']) && is_array($DATA['cart'])) {

    foreach($array['it_id'] as $key=>$val) {

    if(isset($array['ct_chk'][$key]) && $array['ct_chk'][$key]=="1") {

        $TMP['it'][] = $val;

    } else {

        continue;

    }

}

}</p>

<p>

//print_r($TMP['it']);</p>

<p>if(is_array($TMP['it']) && is_array($TMP['it'])) {

    # 견적할 제품이 있음

} else {

    # 견적할 제품이 없음

    echo "<h2>견적서를 출력할 제품이 없습니다.</h2>";

    include_once(G5_PATH.'/tail.sub.php');

    exit;

}</p>

<p>

# 장바구니 DB 가져오기 ---------------------------------------------------------------------------</p>

<p>$s_cart_id = get_session('ss_cart_id');</p>

<p>// $s_cart_id 로 현재 장바구니 자료 쿼리

$qry = " SELECT * FROM {$g5['g5_shop_cart_table']} WHERE od_id = '$s_cart_id' AND it_id IN ( ". implode(",", $TMP['it']) ." ) ORDER BY it_id ";</p>

<p>$res = sql_query($qry);

if(sql_num_rows($res)>0) {

    $idx = 0;

    while($row = sql_fetch_array($res)) {

        $DATA['cart'][$idx] = $row;</p>

<p>        # 옵션DB 가져오기

        $qry2 = " SELECT * FROM {$g5['g5_shop_item_option_table']} WHERE it_id = '{$row['it_id']}' AND io_id='{$row['io_id']}' AND io_type='0' ";

        $res2 = sql_query($qry2);

        if(sql_num_rows($res2)>0) {

            $DATA['opt'][$idx] = sql_fetch_array($res2);

        }</p>

<p>        $idx++;

    }

}</p>

<p>//print_r($DATA);</p>

<p>

# 출력화면 그리기      ---------------------------------------------------------------------------</p>

<p>?></p>

<p>

<style type="text/css">

.print-wrap { width:600px; box-sizing:border-box; margin:5px auto; }

/* 표제부 */

.table-info { border-collapse:collapse; width:100%; }

.table-info * { font-size: 12px;}

.table-info td { border:1px solid #09a4b6; height:20px; }

.table-info .td-row-6 { background:#06899f; color:#ffffff; text-align:center; }

.table-info .td-head { background:#67b9c2; text-align:center; color:#ffffff; }

/* 제품리스트 */

.table-list { border-collapse:collapse; width:100%; margin:20px 0 0 0; }

.table-list * { font-size:12px;}

.table-list td { border:1px solid #09a4b6; height:20px; }

.table-list .td-head { background:#67b9c2; text-align:center; color:#ffffff; }

.table-list .td-body { font-size:11px !important; }

/* 공통 */

.input-1 { width:174px; }

.td-right { text-align:right; }

.td-center { text-align:center; }

/* 기타 */

.div-help { margin:10px 0; color:#2861c8; }

.print-button { width:600px; margin:10px auto; text-align:right; }

.print-button button { padding:4px 10px; background:#2548a5; color:#ffffff; border:0; }

@media print {

    .print-button { display:none; }

}

</style></p>

<p><div class="print-wrap"></p>

<p>    <table class="table-info">

    <col width="20">

    <col width="60">

    <col width="180">

    <col width="20">

    <col width="60">

    <col width="">

    <col width="60">

    <col width="">

    <tr>

        <td class="td-row-6" rowspan="6">의
뢰
자</td>

        <td class="td-head">견적일</td>

        <td class="td-body"><input type="text" class="input-1" value="<?=date("Y-m-d")?>"></td>

        <td class="td-row-6" rowspan="6">공
급
자</td>

        <td class="td-head">등록번호</td>

        <td class="td-body" colspan="3"><?=$default['de_admin_company_saupja_no']?></td>

    </tr>

    <tr>

        <td class="td-head">업체명</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">회사명</td>

        <td class="td-body"><?=$default['de_admin_company_name']?></td>

        <td class="td-head">성명</td>

        <td class="td-body"><?=$default['de_admin_company_owner']?></td>

    </tr>

    <tr>

        <td class="td-head">담당자</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">주소</td>

        <td class="td-body" colspan="3"><?=$default['de_admin_company_addr']?></td>

    </tr>

    <tr>

        <td class="td-head">전화</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">업태</td>

        <td class="td-body"><?=$default['de_biztype_a']?></td>

        <td class="td-head">종목</td>

        <td class="td-body"><?=$default['de_biztype_b']?></td>

    </tr>

    <tr>

        <td class="td-head">팩스</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">전화</td>

        <td class="td-body"><?=$default['de_admin_company_tel']?></td>

        <td class="td-head">팩스</td>

        <td class="td-body"><?=$default['de_admin_company_fax']?></td>

    </tr>

    <tr>

        <td class="td-head">E-mail</td>

        <td class="td-body"><input type="text" class="input-1"></td>

        <td class="td-head">담당자</td>

        <td class="td-body" colspan="3"></td>

    </tr>

    </table></p>

<p>    <table class="table-list">

    <col width="80">

    <col width="80">

    <col width="80">

    <col width="">

    <col width="60">

    <col width="40">

    <col width="70">

    <tr>

        <td class="td-head">제품번호</td>

        <td class="td-head">제품명</td>

        <td class="td-head">형식번호</td>

        <td class="td-head">제품사양</td>

        <td class="td-head">단가</td>

        <td class="td-head">수량</td>

        <td class="td-head">가격</td>

    </tr></p>

<p>    <?

    $total_price = 0;

    $this_price = 0;

                                   

    foreach($DATA['cart'] as $key=>$val) {

        $this_price = ($val['ct_price']+$val['io_price']) * $val['ct_qty'];

        $total_price += $this_price;

        

    ?>

    <tr>

        <td class="td-body"><?php $val['io_id']?></td>

        <td class="td-body"><?php $val['it_name']?></td>

        <td class="td-body"><?php $DATA['opt'][$key]['io_misc01']?></td>

        <td class="td-body"><?php $DATA['opt'][$key]['io_misc02']?></td>

        <td class="td-body td-right"><?=number_format($val['ct_price']+$val['io_price'])?></td>

        <td class="td-body td-center"><?=number_format($val['ct_qty'])?></td>

        <td class="td-body td-right"><?=number_format($this_price)?></td>

    </tr>

    

    

    <?

    } # end foreach;

    ?></p>

<p>    <tr>

        <td class="td-body td-center" colspan="6"><strong>합계금액</strong></td>

        <td class="td-body td-right"><strong><?=number_format($total_price)?></strong></td>

    </tr></p>

<p>

    </table></p>

<p>    <div class="div-help">

        상기 견적내용은 환율에 따라 가격이 변동될 수 있으니 참고용으로만 활용하시기 바랍니다.


        (견적내용 및 입력사항은 서버로 전송되지 않습니다)


        자세한 견적상담을 원하시면 <?=$default['de_admin_company_tel']?>로 전화바랍니다.

    </div></p>

<p></div></p>

<p><div class="print-button">

    <button type="button" onClick="print();">인쇄</button>

    <button type="button" onClick="window.close();">닫기</button>

</div></p>

<p><?</p>

<p>include_once(G5_PATH.'/tail.sub.php');

?><strong>

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

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

Big1
4년 전

$DATA['cart'] 가 null 인 것 같네요. 
if 문을 추가해야할 듯요

if (isset($DATA['cart']) && is_array($DATA['cart'])) {
}

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

답변에 대한 댓글 1개

q
qoqofh
4년 전
print_r($_GET);
print_r($_POST);

이렇게 해서 출력이 되나 확인을 해보았는데 Array ( ) Array ( )

이렇게 뜨네요 ㅠㅠㅠ 값을 불러오지 못하는듯 한데.... 코드좀 봐주실 수 있으실까요 ㅠㅠ?

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

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

로그인