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

무한스크롤 기능 구현

· 8년 전 · 8415 · 10
1. list.php : 스킨/list.skin.php 에 맨 하단에 추가

$(".pageListArea .tbl_head01").append(data); <- 추가될 위치 지정



2. read.page.php : 스킨/read.page.php 파일 추가

여기서는 추가될 형식에 맞춰서 html 수정을 보셔야 합니다.


[주의사항] wr_id 값이 작은 것들을 가져오고 있습니다.

정렬 순서는 잘 맞추서 수정하세요.



list.php

================================
$last_wr_id :
for 문에서 $last_wr_id = $list[$i]["wr_id"]; <-- 이 부분을 넣어주셔야 합니다.


<script>

var page = 2;
var last_wr_id = <?php echo $last_wr_id; ?>;

$(window).scroll(function () {

if ($(window).scrollTop() == $(document).height() - $(window).height()) {

$.post("<?php echo $board_skin_url;?>/read.page.php", {bo_table:"<?=$bo_table;?>", page:page, last_wr_id:last_wr_id}, function (data) {
//$(".pageListArea .tbl_head01").append("<div style='height:500px;'>추가된 페이지</div>");
$(".pageListArea .tbl_head01").append(data);

page++;
});

}
});
</script>

=============================================





read.page.php

=============================================

<?php

include_once('../../../../../../common.php');

$bo_table = $_POST["bo_table"];
$page = $_POST["page"];
$last_wr_id = $_POST["last_wr_id"];
if (!$bo_table || !$page) exit;


$readTable = "g5_jejubbs_write_" . $bo_table;

$sql = " select * from {$readTable} where wr_id < " . $last_wr_id . " order by " . $board["bo_sort_field"] . " limit 0, 20 ";
$result = sql_query($sql);

while ($row = sql_fetch_array($result)) {
$last_wr_id = $row["wr_id"];
//print_r($row);
?>
<div class="list">

<div class="subj"><a href="<?=G5_BBS_URL;?>/board.php?bo_table=<?=$bo_table;?>&wr_id=<?=$row["wr_id"];?>">
<?php echo cut_str($row["wr_subject"], 20, ".."); ?>
</a></div>

<div class="info">
<div style="float:right">조회수: <?php echo $row['wr_hit'] ?></div>
<?php echo $row['wr_name']; ?>&nbsp;( <?php echo cut_str($row['wr_datetime'], 10, ""); ?> )
</div>

</div>
<?php } ?>
<script>
last_wr_id = <?php echo $last_wr_id; ?>;
</script>

=============================================

댓글 작성

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

로그인하기

댓글 10개

8년 전
유용한 정보네요 감사합니다.
감사합니다^^
감사합니다 굿 입니다요 ^^
감사합니다^^
내용중에서
$readTable = "g5_jejubbs_write_" . $bo_table;
는 아래와 같이 변경하는것이 어떨까요?
$readTable = $g5['write_prefix'] . $bo_table;
8년 전
해피정님// 제가 작업한 것에서 가져온거라 생각을 미쳐 못했네여..

해피정님이 올리신 부분이 더 맞을듯하네여.
오오 감사합니다!
7년 전
무한스크롤기능
6년 전
이거 알기 쉽게 정리해주시면 안될까요?
1. list.php : 스킨/list.skin.php 에 맨 하단에 추가 list.php라고 하고 내용은 list.skin.php라고 하니 무슨 말인지 모르겟습니다.
유용한 정보 감사합니다.

게시글 목록

번호 제목
24318
24317
24315
24309
24294
24293
24277
24262
24260
24253
24251
24236
24233
24228
24226
24221
24214
24203
24201
24199
24196
24195
24194
24192
24191
24187
24185
24183
24172
24168