PHP 이전글 , 다음글

<?

function nextpage( $gubun , $tablename , $columname ,  $no )
{

 if( $gubun && $tablename && $columname && $no )
 {

  if( $gubun == 1 ) // 이전 번호 찾기
  {
   $call_info = mysql_fetch_array(mysql_query(" select max($columname) callno from $tablename where $columname < $no "));
  }
  else if ( $gubun == 2 ) // 다음 번호 찾기
  {
   $call_info = mysql_fetch_array(mysql_query(" select min($columname) callno from $tablename where $columname > $no "));
  }
  
  $str = $call_info[callno];
 }
 else
 {
  $str = "" ;
 }
 
 return $str ; 
}



// 사용 ------------------------------------------------------------------------------------------- 

  if( nextpage( 1, '테이블이름' , ''컬럼의이름' , 현재글num ) )
  {
  echo "<input type=button value='이전글' onclick="" >&nbsp;";
  }

  if( nextpage( 2, '테이블이름' , '컬럼의이름' , 현재글num ) )
  {
  echo "&nbsp;<input type=button value='다음글' onclick="" >";
  }
?>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다