답변 7개
Copy
<script>
// 현재 페이지 및 페이지당 가져올 데이터의 개수
let currentPage = 1;
const itemsPerPage = 20;
// "더 보기" 버튼 클릭 이벤트 핸들러
document.getElementById('loadMoreButton').addEventListener('click', loadMoreItems);
function loadMoreItems() {
// 서버로부터 데이터를 가져올 범위 계산
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
// 서버에 데이터를 요청하는 Ajax 호출
const xhr = new XMLHttpRequest();
xhr.open('GET', `/api/data?start=${startIndex}&end=${endIndex}`, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// 서버로부터 데이터를 받아온 후 처리
const responseData = JSON.parse(xhr.responseText);
displayItems(responseData.items);
// 현재 페이지 갱신
currentPage++;
// 더 보기 버튼을 숨길지 여부 결정
if (responseData.totalCount <= endIndex) {
document.getElementById('loadMoreButton').style.display = 'none';
}
}
};
xhr.send();
}
function displayItems(items) {
// 받은 데이터를 화면에 표시하는 로직을 구현
for (const item of items) {
const itemElement = document.createElement('div');
itemElement.textContent = item.wr_1;
document.getElementById('itemsContainer').appendChild(itemElement);
}
}
</script>
<?php
$startIndex = $_GET['start'];
$endIndex = $_GET['end'];
// 데이터베이스에서 startIndex부터 endIndex까지의 데이터 조회
$query = "SELECT wr_1 FROM your_table_name LIMIT $startIndex, $endIndex";
// 쿼리 실행 및 결과 반환
$response = [
'items' => $result, // 조회된 데이터
'totalCount' => $totalCount // 전체 데이터 개수
];
echo json_encode($response);
?>
약 1,000개 행 데이터를 입력한 후 view.skin.php 에 wr_1 필드값을 출력해봤는데 속도가 많이 느려지는데 한번에 출력하는 방법말고
<---이게 무슨 말인가요?
view페이지에 보여지는 것은 해당 게시물 wr_1 하나 인데 느려진다는 것은 무슨 말이며
한번에 출력하지않는 방법이란 무슨 말인가요?
wr_1에 얼마나 긴 값을 넣어서 느껴질 만큼 느려지는가요?
wr_content에 긴 내용을 넣어서 느려졌다는 말이 있던가요?
질문이 이상한 것 같은데요?
MySQL 의 경우 다음 형태의 쿼리에 적절한 페이징 기법을 추가해 응용해볼수 있을것 같습니다.
Copy
/*
-----+---------------------+-----
... | wr_1 | ...
-----+---------------------+-----
... | 1/2/3/4/5 | ...
... | 11/22/33/44/55 | ...
... | 111/222/333/444/555 | ...
-----+---------------------+-----
*/
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(wr_1,'/',2),'/',-2) partial_wr_1 FROM tablename;
/*
+--------------+
| partial_wr_1 |
+--------------+
| 1/2 |
| 11/22 |
| 111/222 |
+--------------+
*/
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(wr_1,'/',4),'/',-2) partial_wr_1 FROM tablename;
/*
+--------------+
| partial_wr_1 |
+--------------+
| 3/4 |
| 33/44 |
| 333/444 |
+--------------+
*/
답변을 작성하려면 로그인이 필요합니다.