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

검색 후 페이징처리 하기 질문입니다. 채택완료

시로님 9년 전 조회 4,502

include_once('./_common.php');

 

 

//$type = "video";

$g5['title']="소모품리스트";

$bo_table = "sub03_02";

 

include_once(G5_PATH.'/head.php');

 

$sql = " SELECT * FROM g5_write_sub03_02 where wr_is_comment = 0 and wr_6 <> '완료' ";

 

if($member['mb_level']=='10'){

    $sql_where ="";

}else if($member['mb_level']=='7'){

    $sql_where =" and wr_subject = '".$member['mb_4']."' ";

}else if($member['mb_level']=='5'){

    $sql_where =" and wr_subject = '".$member['mb_4']."' and wr_5 = '".$member['mb_nick']."' ";

}

 

if($_GET['sfl']){

    $sfl = mysql_escape_string($_GET['sfl']);

    $stx = mysql_escape_string($_GET['stx']);

    $sql_sch = " and ".$sfl." like '".$stx."%' ";

}

 

 

if($_GET['wr_1']) {

$wr_2 = mysql_escape_string($_GET['start_y']."-".$_GET['start_m']."-".$_GET['start_d']);

$wr_3 = mysql_escape_string($_GET['end_y']."-".$_GET['end_m']."-".$_GET['end_d']);

$wr_2 = date("Y-m-d", strtotime($wr_2));

$wr_3 = date("Y-m-d", strtotime($wr_3));

 

$sql_search = " and (wr_1 between '$wr_2' and '$wr_3') ";

}else{

$wr_2 = date("Y-m-d");

$wr_3 = date("Y-m-d");

}

 

$sql .= $sql_where; 

$sql .= $sql_sch;

$sql .= $sql_search;

$sql .= $sql_order;

 

 

//echo $sql;

 

 

$sql_cnt = " SELECT count(*) as cnt FROM g5_write_sub03_02 where wr_is_comment = 0 and wr_6 <> '완료' ";

$sql_cnt .= $sql_where;

$sql_cnt .= $sql_sch;

$sql_cnt .= $sql_search;

 

/* 페이징 시작 */

//페이지 get 변수가 있다면 받아오고, 없다면 1페이지를 보여준다.

if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; }

$row1 = sql_fetch($sql_cnt);

$allPost = $row1['cnt']; //전체 게시글의 수

 

$onePage = 2; // 한 페이지에 보여줄 게시글의 수.

$allPage = ceil($allPost / $onePage); //전체 페이지의 수

    

if($page < 1 && $page > $allPage) {

?>

 

exit;

}

$oneSection = 10; //한번에 보여줄 총 페이지 개수(1 ~ 10, 11 ~ 20 ...)

$currentSection = ceil($page / $oneSection); //현재 섹션

$allSection = ceil($allPage / $oneSection); //전체 섹션의 수

$firstPage = ($currentSection * $oneSection) - ($oneSection - 1); //현재 섹션의 처음 페이지

if($currentSection == $allSection) {

$lastPage = $allPage; //현재 섹션이 마지막 섹션이라면 $allPage가 마지막 페이지가 된다.

} else {

$lastPage = $currentSection * $oneSection; //현재 섹션의 마지막 페이지

}

$prevPage = (($currentSection - 1) * $oneSection); //이전 페이지, 11~20일 때 이전을 누르면 10 페이지로 이동.

$nextPage = (($currentSection + 1) * $oneSection) - ($oneSection - 1); //다음 페이지, 11~20일 때 다음을 누르면 21 페이지로 이동.

 

/*$date_paging = "&sfl=".$sfl."&stx=".$stx."&wr_1=".$_GET['wr_1']."&wr_2=".($_GET['start_y']."-".$_GET['start_m']."-".$_GET['start_d'])."&wr_3=".($_GET['end_y']."-".$_GET['end_m']."-".$_GET['end_d']);*/

$date_paging = "&sfl=".$sfl."&stx=".$stx."&wr_1=".$_GET['wr_1']."&start_y=".($_GET['start_y']."&start_m=".$_GET['start_m']."&start_d".$_GET['start_d'])."&end_y=".($_GET['end_y']."&end_m=".$_GET['end_m']."&end_d=".$_GET['end_d']);

 

print_r($sfl);

print_r($stx);

print_r($_GET['wr_1']);

print_r($_GET['start_y']);

print_r($_GET['start_m']);

print_r($_GET['start_d']);

print_r($_GET['end_y']);

print_r($_GET['end_m']);

print_r($_GET['end_d']);

$paging = '

    '; // 페이징을 저장할 변수

     

    //첫 페이지가 아니라면 처음 버튼을 생성

    if($page != 1) { 

    $paging .= '

  • 처음
  • ';

    }

    //첫 섹션이 아니라면 이전 버튼을 생성

    if($currentSection != 1) { 

    $paging .= '

  • 이전
  • ';

    }

    for($i = $firstPage; $i <= $lastPage; $i++) {

    if($i == $page) {

    $paging .= '

  • ' . $i . '
  • ';

    } else {

    $paging .= '

  • ' . $i . '
  • ';

    }

    }

    //마지막 섹션이 아니라면 다음 버튼을 생성

    if($currentSection != $allSection) { 

    $paging .= '

  • 다음
  • ';

    }

    //마지막 페이지가 아니라면 끝 버튼을 생성

    if($page != $allPage) { 

    $paging .= '

  • ';

    }

    $paging .= '

';

/* 페이징 끝 */

$currentLimit = ($onePage * $page) - $onePage; //몇 번째의 글부터 가져오는지

$sqlLimit = ' limit ' . $currentLimit . ', ' . $onePage; //limit sql 구문

$sql = $sql . $sqlLimit; //원하는 개수만큼 가져온다. (0번째부터 20번째까지

$result = sql_query($sql);

 

 

    $list_num = $allPost - ($page - 1) * $onepage;

?>

 

 

   

 

* 기간별 검색시 체크 

/>

부터 까지

 

 

 

페이징처리가 전체게시물이 나올때는 되지만 검색 후의 페이징처리가 되지 않습니다.

$date_paging 부분을 계속 손보고 있는데 쉽지 않네요

 


사진에서 print_r로 찍어봤을때 나오는 게 맨 위에부분이고

 

검색된 후에 2페이지로 넘어가면 저렇게 검색어가 깨지면서 페이징이 되지 않습니다.

 

wr_1값과 start_d값도 나오지 않는데 해결방법이 있을까요.?ㅠ

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

답변 1개

채택된 답변
+20 포인트

$date_paging = "&sfl=".$sfl."&stx=".urlencode($stx)

다음 페이지로 넘어갔을 때 한글이 저렇게 깨지면 인코딩을 하면 됩니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

시로님
9년 전
오 해결되었습니다. 감사합니다!

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

답변을 작성하려면 로그인이 필요합니다.

로그인