본인이 쓴 게시물만 최신 게시판에 출력 채택완료
승슝
3년 전
조회 1,854
안녕하세요,
최신게시판에 본인이 쓴 게시물만 나올 수 있도록 제한을 하고 싶습니다.
그래서 latest.skin.php 에 조건문을 넣어서 진행을 했습니다.
</p>
<p> for ($i=0; $i<$list_count; $i++) { </p>
<p> </p>
<p> if($list[$i]['mb_id'] == $member['mb_id']){</p>
<p>
이런식으로 조건문을 넣었습니다.
그런데 문제가 본인이 쓴 게시물이 6번 돌아갈 동안 없으면 나오지 값이 나오지 않습니다.
이 문제를 해결하고 싶어서 for문안에 있는 변수 $list_count를 if($list[$i]['mb_id'] == $member['mb_id']) 조건에 맞지 않으면 $list_count = $list_count +1을 해보았는데 이렇게 하면 페이지가 돌아가지 않더라구요
최소 최신글 3개는 보일 수 있게 하고 싶습니다
그리고 $list_count가 아니라 숫자 20을 넣어도 basic>group.php에서
</p>
<p>echo latest('theme/basic', $row['bo_table'], 6, 25);</p>
<p>
저기 6을 같이 증가 시키지 않으면 출력문구도 제대로 출력이 되지 않았습니다.
해결 방법에 대해 조언 부탁드립니다.
감사합니다.
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
답변에 대한 댓글 5개
�
엑스엠엘
3년 전
�
승슝
3년 전
답변 감사합니다. 말씀하신대로 쿼리문을 수정하였는데 갑자기 mb_id가 한가지로 고정되어 다른 아이디로 접속하여도 계속 동일한 게시물만 표출되는 상태입니다.
이쪽 쿼리문을 돌지 않는 것 같아 쿼리문을 찍어 보았는데 나오지 않는 것으로 보아 무슨 문제가 있는 것 같기는 한데 정확한 해결방법을 찾지 못한 상황입니다.
[code]
<?php
if (!defined('_GNUBOARD_')) exit;
@include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// 최신글 추출
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
// $member,$is_admin 신규 추가
global $g5, $member,$is_admin;
if (!$skin_dir) $skin_dir = 'basic';
$time_unit = 3600; // 1시간으로 고정
if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
if (G5_IS_MOBILE) {
$latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
if(!is_dir($latest_skin_path))
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
} else {
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
}
$skin_dir = $match[1];
} else {
if(G5_IS_MOBILE) {
$latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
$latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
$latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir;
}
}
$caches = false;
if(G5_USE_CACHE) {
$cache_file_name = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key();
$caches = g5_get_cache($cache_file_name, (int) $time_unit * (int) $cache_time);
$cache_list = isset($caches['list']) ? $caches['list'] : array();
g5_latest_cache_data($bo_table, $cache_list);
}
if( $caches === false ){
$list = array();
$board = get_board_db($bo_table, true);
if( ! $board ){
return '';
}
$bo_subject = get_text($board['bo_subject']);
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
// if($member['mb_id'] == 'admin'){
// $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} "; //기존 sql문
// }else{
// $sql = " select * from {$tmp_write_table} where mb_id='{$member['mb_id']}' and wr_is_comment = 0 order by wr_num limit 0, {$rows} ; //기존 본인이 쓴 글만 보이는 sql문,
// }
$sql = " select * from {$tmp_write_table} where mb_id='{$member['mb_id']}' and wr_is_comment = 0 order by wr_num limit 0, {$rows} "; //기존 본인이 쓴 글만 보이는 sql문
echo "tmp_write_table",$tmp_write_table;
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {
try {
unset($row['wr_password']); //패스워드 저장 안함( 아예 삭제 )
} catch (Exception $e) {
}
$row['wr_email'] = ''; //이메일 저장 안함
if (strstr($row['wr_option'], 'secret')){ // 비밀글일 경우 내용, 링크, 파일 저장 안함
$row['wr_content'] = $row['wr_link1'] = $row['wr_link2'] = '';
$row['file'] = array('count'=>0);
}
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
$list[$i]['first_file_thumb'] = (isset($row['wr_file']) && $row['wr_file']) ? get_board_file_db($bo_table, $row['wr_id'], 'bf_file, bf_content', "and bf_type between '1' and '3'", true) : array('bf_file'=>'', 'bf_content'=>'');
$list[$i]['bo_table'] = $bo_table;
// 썸네일 추가
if($options && is_string($options)) {
$options_arr = explode(',', $options);
$thumb_width = $options_arr[0];
$thumb_height = $options_arr[1];
$thumb = get_list_thumbnail($bo_table, $row['wr_id'], $thumb_width, $thumb_height, false, true);
// 이미지 썸네일
if($thumb['src']) {
$img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';
$list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';
// } else {
// $img_content = '<img src="'. G5_IMG_URL.'/no_img.png'.'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" class="no_img">';
}
}
if(! isset($list[$i]['icon_file'])) $list[$i]['icon_file'] = '';
}
g5_latest_cache_data($bo_table, $list);
if(G5_USE_CACHE) {
$caches = array(
'list' => $list,
'bo_subject' => sql_escape_string($bo_subject),
);
g5_set_cache($cache_file_name, $caches, (int) $time_unit
[/code]
이쪽 쿼리문을 돌지 않는 것 같아 쿼리문을 찍어 보았는데 나오지 않는 것으로 보아 무슨 문제가 있는 것 같기는 한데 정확한 해결방법을 찾지 못한 상황입니다.
[code]
<?php
if (!defined('_GNUBOARD_')) exit;
@include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// 최신글 추출
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
// $member,$is_admin 신규 추가
global $g5, $member,$is_admin;
if (!$skin_dir) $skin_dir = 'basic';
$time_unit = 3600; // 1시간으로 고정
if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
if (G5_IS_MOBILE) {
$latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
if(!is_dir($latest_skin_path))
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
} else {
$latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
$latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
}
$skin_dir = $match[1];
} else {
if(G5_IS_MOBILE) {
$latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
$latest_skin_url = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
$latest_skin_url = G5_SKIN_URL.'/latest/'.$skin_dir;
}
}
$caches = false;
if(G5_USE_CACHE) {
$cache_file_name = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key();
$caches = g5_get_cache($cache_file_name, (int) $time_unit * (int) $cache_time);
$cache_list = isset($caches['list']) ? $caches['list'] : array();
g5_latest_cache_data($bo_table, $cache_list);
}
if( $caches === false ){
$list = array();
$board = get_board_db($bo_table, true);
if( ! $board ){
return '';
}
$bo_subject = get_text($board['bo_subject']);
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
// if($member['mb_id'] == 'admin'){
// $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} "; //기존 sql문
// }else{
// $sql = " select * from {$tmp_write_table} where mb_id='{$member['mb_id']}' and wr_is_comment = 0 order by wr_num limit 0, {$rows} ; //기존 본인이 쓴 글만 보이는 sql문,
// }
$sql = " select * from {$tmp_write_table} where mb_id='{$member['mb_id']}' and wr_is_comment = 0 order by wr_num limit 0, {$rows} "; //기존 본인이 쓴 글만 보이는 sql문
echo "tmp_write_table",$tmp_write_table;
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {
try {
unset($row['wr_password']); //패스워드 저장 안함( 아예 삭제 )
} catch (Exception $e) {
}
$row['wr_email'] = ''; //이메일 저장 안함
if (strstr($row['wr_option'], 'secret')){ // 비밀글일 경우 내용, 링크, 파일 저장 안함
$row['wr_content'] = $row['wr_link1'] = $row['wr_link2'] = '';
$row['file'] = array('count'=>0);
}
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
$list[$i]['first_file_thumb'] = (isset($row['wr_file']) && $row['wr_file']) ? get_board_file_db($bo_table, $row['wr_id'], 'bf_file, bf_content', "and bf_type between '1' and '3'", true) : array('bf_file'=>'', 'bf_content'=>'');
$list[$i]['bo_table'] = $bo_table;
// 썸네일 추가
if($options && is_string($options)) {
$options_arr = explode(',', $options);
$thumb_width = $options_arr[0];
$thumb_height = $options_arr[1];
$thumb = get_list_thumbnail($bo_table, $row['wr_id'], $thumb_width, $thumb_height, false, true);
// 이미지 썸네일
if($thumb['src']) {
$img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';
$list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';
// } else {
// $img_content = '<img src="'. G5_IMG_URL.'/no_img.png'.'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" class="no_img">';
}
}
if(! isset($list[$i]['icon_file'])) $list[$i]['icon_file'] = '';
}
g5_latest_cache_data($bo_table, $list);
if(G5_USE_CACHE) {
$caches = array(
'list' => $list,
'bo_subject' => sql_escape_string($bo_subject),
);
g5_set_cache($cache_file_name, $caches, (int) $time_unit
[/code]
�
엑스엠엘
3년 전
이쪽 쿼리문을 돌지 않는 것 같아 쿼리문을 찍어 보았는데
나오지 않는 것으로 보아
==
echo $sql;
했는데 아무것도 찍히지 않았다는 것은 cache 때문일 수 있습니다.
삭제하시거나 사용 안 함으로 설정하시고
다시 해 보세요.
나오지 않는 것으로 보아
==
echo $sql;
했는데 아무것도 찍히지 않았다는 것은 cache 때문일 수 있습니다.
삭제하시거나 사용 안 함으로 설정하시고
다시 해 보세요.
�
승슝
3년 전
sql문이 if( $caches === false ){ 이 조건문 안에 잇는데 이 조건문을 아예 삭제하고 진행해도 될까요?? 도대체 $caches === false이것의 뜻이 무엇인지 아실까요???
�
승슝
3년 전
아니면 혹시 처음에 알려주셨던
================================
// 최신글 추출
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
global $g5;
global $member; // 추가
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
// where에서 and mb_id='{$member['mb_id']}' 추가
===================================================
이 내용에서
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
이 두문장이 글로벌 바로 아래 들어가야 되는 건가요??
위치를 수정해야되는 건가 싶어서요~
================================
// 최신글 추출
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
global $g5;
global $member; // 추가
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
// where에서 and mb_id='{$member['mb_id']}' 추가
===================================================
이 내용에서
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
이 두문장이 글로벌 바로 아래 들어가야 되는 건가요??
위치를 수정해야되는 건가 싶어서요~
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
// $cache_time 캐시 갱신시간
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
global $g5;
global $member; // 추가
$tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
// where에서 and mb_id='{$member['mb_id']}' 추가
끝으로 로그인이 안 되어 있는 상태를 어떻게 표현할지 고민해 보세요.