페이지 만들기

2021. 3. 26. 08:42웹 프로그래밍/PHP

<?php
$query = "SELECT count(1) AS total FROM post_requester WHERE status = 'O' ";
$result = mysql_query($query);
$total = mysql_fetch_assoc($result);
$limit2 = 15;
$total = ceil($total['total']/$limit2);
$_REQUEST['page'] = $_GET['page'] ? $_GET['page'] : 1;


/* 1~10, 11~20, 21~30 페이지 만들기 */
$page_list_start = ceil($_REQUEST['page']*0.1)*10 - 9;
if($page_list_start > $total){
	$page_list_start = $total;
}
if($page_list_start < 1){
	$page_list_start = 1;
}
$page_list_end =ceil($_REQUEST['page']*0.1)*10;
if($page_list_end > $total){
	$page_list_end = $total;
}
if($page_list_end < 1){
	$page_list_end = 1;
}

$limit1 = $_GET['page'] ? $_GET['page']*$limit2-$limit2 : 0;
?>
<div class="page">
<?
$left = ceil($_REQUEST['page']*0.1)*10 -19;
if($left < 1){
	$left = 1;
}
echo '<a href=\'?bid='.$_REQUEST[bid].'&search_radio='.$_REQUEST['search_radio'].'&category='.$_REQUEST['category'].'&search_input='.$_REQUEST['search_input'].'&page='. $left .'\'><span><</span></a>';
?>
<?
for(;$page_list_start<=$page_list_end ;$page_list_start++){
	if($page_list_start == $_REQUEST['page']){
		echo '<a href=\'?bid='.$_REQUEST[bid].'&search_radio='.$_REQUEST['search_radio'].'&category='.$_REQUEST['category'].'&search_input='.$_REQUEST['search_input'].'&page='. $page_list_start .'\'><span class=\'selected\'>'.$page_list_start.'</span>';
	}
	else{
		echo '<a href=\'?bid='.$_REQUEST[bid].'&search_radio='.$_REQUEST['search_radio'].'&category='.$_REQUEST['category'].'&search_input='.$_REQUEST['search_input'].'&page='. $page_list_start .'\'><span>'.$page_list_start.'</span></a>';
	}
}
?>
<?
$right = ceil($_REQUEST['page']*0.1)*10 +1;
if($right > $total){
	$right = $total;
}
echo '<a href=\'?bid='.$_REQUEST[bid].'&search_radio='.$_REQUEST['search_radio'].'&category='.$_REQUEST['category'].'&search_input='.$_REQUEST['search_input'].'&page='. $right .'\'><span>></span></a>';
?>

 

728x90

'웹 프로그래밍 > PHP' 카테고리의 다른 글

2중배열에서 값있는지 찾기  (0) 2021.08.04
전화번호 출력 정규식  (0) 2021.04.21
DB에 따옴표(' 또는 ") 입력시 치환  (0) 2021.03.26
HTTP -> HTTPS  (0) 2021.03.26
이모지 제거  (0) 2020.09.15