답변 1개
아래의 내용을 한번 참고해 보시겠어요..
1. 최근 본 게시물 기록 (게시물을 열 때마다 해당 게시물 정보를 세션에 저장합니다.)
// 최근 본 게시물 최대 저장 개수 $max_recent_posts = 10;
// 현재 게시물 정보 $bo_table = $_GET['bo_table']; // 게시판 ID $wr_id = $_GET['wr_id']; // 게시물 ID $view_post = array('bo_table' => $bo_table, 'wr_id' => $wr_id);
// 세션에 최근 본 게시물이 있는지 확인하고 없으면 초기화 if (!isset($_SESSION['recent_posts'])) { $_SESSION['recent_posts'] = array(); }
// 현재 게시물 정보가 이미 저장되어 있는지 확인하고 있으면 제거 foreach ($_SESSION['recent_posts'] as $key => $post) { if ($post['bo_table'] == $bo_table && $post['wr_id'] == $wr_id) { unset($_SESSION['recent_posts'][$key]); break; } }
// 최근 본 게시물 배열의 앞에 현재 게시물 추가 array_unshift($_SESSION['recent_posts'], $view_post);
// 최근 본 게시물 개수가 최대 개수를 초과하면 마지막 요소 제거 if (count($_SESSION['recent_posts']) > $max_recent_posts) { array_pop($_SESSION['recent_posts']); }
// 최근 본 게시물 세션을 다시 저장 $_SESSION['recent_posts'] = array_values($_SESSION['recent_posts']); ?>
2. 최근 본 게시물 출력 (저장된 최근 본 게시물 정보를 화면에 출력합니다.)
// 최근 본 게시물이 세션에 저장되어 있는지 확인 if (isset($_SESSION['recent_posts']) && count($_SESSION['recent_posts']) > 0) { echo "
최근 본 게시물
- ";
- {$subject} "; } }
// 최근 본 게시물 순서대로 출력 foreach ($_SESSION['recent_posts'] as $post) { $bo_table = $post['bo_table']; $wr_id = $post['wr_id'];
// 게시물 제목 가져오기 $sql = "SELECT wr_subject FROM g5_write_{$bo_table} WHERE wr_id = '{$wr_id}'"; $result = sql_query($sql); $row = sql_fetch_array($result);
// 게시물 제목이 있는 경우 출력 if ($row) { $subject = $row['wr_subject']; echo "
echo "
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인