본문 바로가기
웹프로그램

PHP 게시판 페이징 처리

by 세이박스 2008. 10. 14.
반응형

$skippage=10;
$pagesize=20;
if(!$page){
$page=1;
}
$kkk=($page-1)*$pagesize;
 
if(!$cmd){
  $qry_cnt="SELECT * FROM tech WHERE field_no=$field_no";
  $qry="SELECT * FROM tech WHERE field_no=$field_no ORDER BY
  wdate DESC LIMIT $kkk, $pagesize";
}else{
  switch($sec){
    case 1:
      $qry_cnt="SELECT * FROM tech WHERE field_no=$field_no AND subject LIKE '%$string%'";
      $qry="SELECT * FROM tech  WHERE field_no=$field_no AND subject
  LIKE '%$string%' ORDER BY wdate DESC LIMIT $kkk, $pagesize";
      break;
    case 2:
      $qry_cnt="SELECT * FROM tech  WHERE field_no=$field_no AND content LIKE '%$string%'";
      $qry="SELECT * FROM tech  WHERE field_no=$field_no AND content
  LIKE '%$string%' ORDER BY wdate DESC LIMIT $kkk, $pagesize";
      break;
    }
}

$rs_cnt=mysql_query($qry_cnt);
$total_record=mysql_num_rows($rs_cnt);
$totalpage=ceil($total_record/$pagesize);
 
$rs=mysql_query($qry);
if(!$rs){
  Error();
}


##########################################

<?
  $i=$total_record-$pagesize*($kkk/$pagesize);
  while($row=mysql_fetch_array($rs)){
?>
 
<?echo $i?>

<?
 $i--;
}
?>

############################################

<!--글 번호 시작//-->
<?
  $temp1=ceil($page/$skippage)-1;
  $temp2=$temp1*$pagesize;
  $temp3=ceil($totalpage/$skippage)-1;

  $prev=$temp2;
  if($prev>0){
    echo "<a href='./list.php?page=1&field_no=$field_no&cmd=
$cmd&sec=$sec&string=$string'><font size=-2>[맨앞]</font></a>";
    echo "<a href='./list.php?page=$prev&field_no=$field_no&cmd=
$cmd&sec=$sec&string=$string'>≪</a>";
  }

  $pagelist=$temp2;

  for($j=1;$j<=$skippage;$j++){
    $pagelist=$temp2+$j;
    if($totalpage<$pagelist){
      break;
    }
    if($pagelist<>$page){
      echo "<a href='./list.php?page=$pagelist&field_no=$field_no&cmd=
  $cmd&sec=$sec&string=$string'><font size=-2>[$pagelist]</font></a>";
    }else {
      echo "<b>".$pagelist."</b>";
    }
}

  $post=$temp2+$skippage+1;

  if($temp1<$temp3){
    echo "<a href='./list.php?page=$post&field_no=$field_no&cmd=$cmd
&sec=$sec&string=$string'>≫</a>";
    echo "<a href='./list.php?page=$totalpage&field_no=$field_no&cmd=$cmd
&sec=$sec&string=$string'><font size=-2>[맨뒤]</font></a>";
  }
?>   
<!--글 번호 끝//-->
</pre>

반응형