리스트에서 여분필드가 특정값인 것만 출력하기
본문
게시판 리스트에서
여분필드의 특정 값이 있는 리스트만 출력하려고 합니다.
그런데 한 페이지에서 리스트를 두개를 출력을 하려고 하는데
어떻게 해결을 해야할까요?
위쪽 리스트에는 wr_1에 1이 있는 리스트,
아래쪽 리스트에는 wr_1에 2가 있는 리스트
이런식으로 출력을 하려고 합니다.
list.php에 bo_table이 특정 테이블일경우만 $ist를 다르게 뽑아줘야 할까요?
가능하다면 스킨에서 수정을 하고싶은데... list.php를 수정하는 것 이외에는 도무지 방법을 모르겠네요.
list.php에서 수정을 해야 한다고 하면 어느부분을 어떻게 고쳐야 할까요?
답변 3
list.php 30번줄 쯤 사이에,
// 사용자 코드 실행
@include_once($board_skin_path.'/list.search.skin.php');
넣으시고,
list.php 에 50줄쯔음에 if($sca || $stx) 부분 찾으셔서,
// 분류 선택 또는 검색어가 있다면
$stx = trim($stx);
if ($sca || $stx) {
$sql_search = get_sql_search($sca, $sfl, $stx, $sop);
// 가장 작은 번호를 얻어서 변수에 저장 (하단의 페이징에서 사용)
$sql = " select MIN(wr_num) as min_wr_num from {$write_table} ";
$row = sql_fetch($sql);
$min_spt = (int)$row['min_wr_num'];
if (!$spt) $spt = $min_spt;
$sql_search .= " and (wr_num between {$spt} and ({$spt} + {$config['cf_search_part']})) ";
// 원글만 얻는다. (코멘트의 내용도 검색하기 위함)
$sql = " SELECT COUNT(DISTINCT `wr_parent`) AS `cnt` FROM {$write_table} WHERE {$sql_search} {$sql_addlist}";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
/*
$sql = " select distinct wr_parent from {$write_table} where {$sql_search} ";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);
*/
} else {
$sql_search = "";
// 원글만 얻는다. (코멘트의 내용도 검색하기 위함)
$sql = " select distinct wr_parent from {$write_table} where (1) {$sql_search} {$sql_addlist}";
$result = sql_query($sql);
$total_count = mysql_num_rows($result);
}
이렇게 넣으시고
그다음으로 list.php 160줄 즈음에 if($sca || $stx) 찾으셔서
if ($sca || $stx) {
$sql = " select distinct wr_parent from {$write_table} where {$sql_search} {$sql_addlist} {$sql_order} limit {$from_record}, $page_rows ";
} else {
$sql = " select * from {$write_table} where wr_is_comment = 0 {$sql_addlist}";
if(!empty($notice_array))
$sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
$sql .= " {$sql_order} limit {$from_record}, $page_rows ";
}
넣어주시고, 마지막으로
skin/board/보드명/list.search.skin.php 에
if ($wr_1){
$sql_addlist .= " and wr_1='특정값' ";
$qstr .= "&wr_1=$wr_1";
}
넣어주시면, wr_1 로도 검색이 됩니다.
약간 요약하자면, list에 검색 핵심소스에, $sql_addlist 라는 임의의 변수를 where에 넣어주고
각 스킨의 $sql_addlist에 대응할수 있도록, 스킨에 list.search.skin.php를 만들어서 각 필드나, 검색컬럼에 맞도록 검색 소스를 넣어주는 작업을 하는 겁니다.
!-->!-->
list.search.skin.php에서
$sql_addlist .= " and (wr_1='1' or wr_1='2' )";
$qstr .= "&wr_1=$wr_1";
이렇게 1일때랑 2일때의 list를 갖고 오셔서,
list.skin.php에서
if($list[$i]['wr_1'] == 1) 일 경우랑
if($list[$i]['wr_1'] == 2) 일 경우를 나눠서,
뿌려주면 되지 않을까요?