꾸준히 안타치기
paging 본문
반응형
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pagination</title>
</head>
<body>
<?php
// connect to database
$con = mysqli_connect('localhost','root','');
mysqli_select_db($con, 'pagination');
// define how many results you want per page
$results_per_page = 10;
// find out the number of results stored in database
$sql='SELECT * FROM alphabet';
$result = mysqli_query($con, $sql);
$number_of_results = mysqli_num_rows($result);
// determine number of total pages available
$number_of_pages = ceil($number_of_results/$results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// determine the sql LIMIT starting number for the results on the displaying page
$this_page_first_result = ($page-1)*$results_per_page;
// retrieve selected results from database and display them on page
$sql='SELECT * FROM alphabet LIMIT ' . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)) {
echo $row['id'] . ' ' . $row['alphabet']. '<br>';
}
// display the links to the pages
for ($page=1;$page<=$number_of_pages;$page++) {
echo '<a href="index.php?page=' . $page . '">' . $page . '</a> ';
}
?>
</body>
</html>
mysql연결된 php 페이징
www.notion.so/e7ea22382c1f4a98a0f067f9f1e791e4#4527f052f0434f61986bf3a9381c2495
반응형
'Server & DB' 카테고리의 다른 글
에디터 붙이기 (0) | 2021.03.23 |
---|---|
이전 / 다음이 있는 페이징 (0) | 2021.03.23 |
쿠키와 세션 (0) | 2021.03.20 |
Mysql workbench (0) | 2021.03.17 |
php+ mysql 로그인/ 회원가입/로그아웃 (0) | 2021.03.17 |
Comments