페이지네이션 오류

페이지네이션 오류

QA

페이지네이션 오류

본문

안녕하세요. 존경하는 고수님들. 바쁘신 시간이지만 혹시 도움을 주실 수 있으시면 답변 부탁드립니다.

 

영카트에서 전체 상품이 나타는 페이지를 제작하려 하는데

페이지네이션에 오류가 생기네요

 

2626825656_1663745564.3243.jpg2626825656_1663745574.6243.jpg

 

총 21개 상품이고 20개 상품씩 끊어서 페이지를 매기는데

1페이지도 21개 상품, 2페이지도 21개 상품이 전부 나옵니다.

 

아래 코드를 넣어놓았습니다.

많은 조언 부탁드립니다.

 

 

 

 


<?php
include_once('./_common.php');
$g5['title'] = '전체상품';
include_once(G5_THEME_MSHOP_PATH.'/shop.head.php');
?>

<div id="sidx">
<section class="sct_wrap">
    <header>
        <h2><a href="#">전체상품</a></h2>
    </header>
    <?php
//---------------- 여기부터
 $skin_file = G5_MSHOP_SKIN_PATH .'/main.10.skin.php'; //스킨명(기존 것을 사용하거나 새로이 만들거나)
 $item_mod = 4; //한줄당 갯수
 $item_rows = 5; //줄 수
 $items = $item_mod * $item_rows;
 $item_width= 480; //이미지 가로
 $item_height = 480; //이미지 세로
 $sql = " select * from {$g5['g5_shop_item_table']} where it_use = '1' order by it_update_time desc ";
        if ($page < 1) $page = 1;
        // 시작 레코드 구함
        $from_record = ($page - 1) * $items;
 $list = new item_list($skin_file, $item_mod , $item_rows , $item_width, $item_height);
 $list->set_query($sql);
//---------- 여기까지
    $list->set_is_page(true);
    $list->set_from_record($from_record);
    $list->set_view('it_img', true);
    $list->set_view('it_name', true);
    $list->set_view('it_basic', true);
    $list->set_view('it_cust_price', true);
    $list->set_view('it_price', true);
    $list->set_view('it_icon', true);
    echo $list->run();
    
    
       // where 된 전체 상품수
        $total_count = $list->total_count;
        // 전체 페이지 계산
        $total_page  = ceil($total_count / 20);
    ?>
    <?php
$qstr1 .='&sort='.$sort.'&sortodr='.$sortodr;
echo get_paging($config['cf_mobile_pages'], $page, $total_page, $_SERVER['SCRIPT_NAME'].'?'.$qstr1.'&page=');
?>
</section>
</div>
<?php
include_once(G5_THEME_MSHOP_PATH.'/shop.tail.php');
?>

이 질문에 댓글 쓰기 :

답변 1



$sql = " select * from {$g5['g5_shop_item_table']} where it_use = '1' order by it_update_time desc ";
        if ($page < 1) $page = 1;
        // 시작 레코드 구함
        $from_record = ($page - 1) * $items;

이부분을

다음과 같이 변경해보세요


 

        if ($page < 1) $page = 1;
        // 시작 레코드 구함
        $from_record = ($page - 1) * $items;

$sql = " select * from {$g5['g5_shop_item_table']} where it_use = '1' order by it_update_time desc limit $from_record, $item_rows  "; 

제가 수정하라고 한부분이
보여주신 로직의 일부분인건 맞죠?
설마 하단을다 삭제하신건 아니죠?

삭제하신게 아니라면
페이지가 안나올리가 없을텐데요


<?php
include_once('./_common.php');
$g5['title'] = '전체상품';
include_once(G5_THEME_MSHOP_PATH.'/shop.head.php');
?>

<div id="sidx">
<section class="sct_wrap">
    <header>
        <h2><a href="#">전체상품</a></h2>
    </header>
    <?php
//---------------- 여기부터
 $skin_file = G5_MSHOP_SKIN_PATH .'/main.10.skin.php'; //스킨명(기존 것을 사용하거나 새로이 만들거나)
 $item_mod = 4; //한줄당 갯수
 $item_rows = 5; //줄 수
 $items = $item_mod * $item_rows;
 $item_width= 480; //이미지 가로
 $item_height = 480; //이미지 세로
        if ($page < 1) $page = 1;
        // 시작 레코드 구함
        $from_record = ($page - 1) * $items;
 $sql = " select * from {$g5['g5_shop_item_table']} where it_use = '1' order by it_update_time desc  
 limit $from_record, $items ";  // 이부분만 변경한겁니다.

 $list = new item_list($skin_file, $item_mod , $item_rows , $item_width, $item_height);
 $list->set_query($sql);
//---------- 여기까지
    $list->set_is_page(true);
    $list->set_from_record($from_record);
    $list->set_view('it_img', true);
    $list->set_view('it_name', true);
    $list->set_view('it_basic', true);
    $list->set_view('it_cust_price', true);
    $list->set_view('it_price', true);
    $list->set_view('it_icon', true);
    echo $list->run();
    
    
       // where 된 전체 상품수
        $total_count = $list->total_count;
        // 전체 페이지 계산
        $total_page  = ceil($total_count / 20);
    ?>
    <?php
$qstr1 .='&sort='.$sort.'&sortodr='.$sortodr;
echo get_paging($config['cf_mobile_pages'], $page, $total_page, $_SERVER['SCRIPT_NAME'].'?'.$qstr1.'&page=');
?>
</section>
</div>
<?php
include_once(G5_THEME_MSHOP_PATH.'/shop.tail.php');
?>

위와같이 하신게 맞나요?

set_query
를 사용하셔서
작동하는 결과값을 찍어보면서 확인하셔야 할것같네요

답변란으로 추측하면서  답으로는 쉽지않을것같고
실제로 echo문으로 total_record값을 찍어보면서 역추적으로 접근해서 확인하시는수밖에 없을것 같습니다.
어딘가 조건이 줄어들게 작동하는것을 찾아서 해결해야할것으로 보여지네요

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

회원로그인

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