조회수,추천수 별로 일정기간의 게시물 추출 > Web Development

본문 바로가기
  • kb@lovelet.com
사이트 내 전체검색

RESOURCES Web Development

조회수,추천수 별로 일정기간의 게시물 추출

페이지 정보

본문

조회수,추천수 별로 일정기간의 게시물 추출
ex) 8월 1일~8월10일 까지의 글중 추천수가 가장높은글 또는 8월 1일~8월10일 까지의 글중 조회수가 가장높은글

http://www.nzeo.com/bbs/zboard.php?id=cgi_tip&page=1&sn1=&divpage=1&sn=off&ss=on&sc=off&keyword=최근&select_arrange=headnum&desc=asc&no=6118
위에 건우님/김기엽님의 글을 참고하여 약간 수정하여 원하는 간격으로 게시물을 조회순이나 추천순으로 추출하는 팁을 만들어 보았습니다

http://www.nzeo.com/bbs/zboard.php?id=cgi_tip&page=1&sn1=&divpage=1&sn=off&ss=on&sc=off&keyword=조회&select_arrange=headnum&desc=asc&no=1831
위에 Mr.JH 님의 글을 참고하여 약간 수정하여 원하는 간격으로 게시물을 조회순이나 추천순으로 추출하는 팁을 만들어 보았습니다

삭제원하시면 쪽지 주세요. 자삭하겠습니다.

미리보기 주소 : http://220.95.232.105/bbs/zboard.php?id=homepr

//-----------------------------------------------------------------------------
outlogin.php 파일을 열어주세요~

아래부분을 복사해주세요
//---------------------------------------------------------
        // 최근 글 목록 (일반 게시판 형)
        function print_bbs($skinname, $title, $id, $num=5, $textlen=30, $datetype="Y/m/d") {
                global $_zb_path, $_zb_url, $connect, $t_board, $admin_table;

                if(!$skinname||!$id||!$title) return;

                $str = zReadFile($_zb_path."latest_skin/".$skinname."/main.html");
                if(!$str) {
                        echo "지정하신 $skinname 이라는 최근목록 스킨이 존재하지 않습니다<br>";
                        return;
                }

                $setup = mysql_fetch_array(mysql_query("select use_alllist from $admin_table where name='$id'"));
                if($setup[use_alllist]) $target = "zboard.php?id=".$id;
                else $target = "view.php?id=".$id;

                $result = mysql_query("select * from $t_board"."_$id where is_secret=0 order by no desc limit $num", $connect) or die(mysql_error());


                $tmpStr = explode("[loop]",$str);
                $header = $tmpStr[0];
                $tmpStr2 = explode("[/loop]",$tmpStr[1]);
                $loop = $tmpStr2[0];
                $footer = $tmpStr2[1];

                // 공지사항 형식을 만들때 사용
                if(eregi("\\[notice\\_",$header)) {
                        $data=mysql_fetch_array($result);
                        $memo = stripslashes($data[memo]);
                        if($data[use_html]<2) $memo = nl2br($memo);
                        else $memo = strip_tags($memo);
                        $filename1 = $data[file_name1];
                        $filename2 = $data[file_name2];
                        if(eregi("\\.gif|\\.jpg",$filename1))$uploadimage1 = "<img src=".$_zb_url.$filename1." border=0 align=left><br>"; else $uploadimage1="";
                        if(eregi("\\.gif|\\.jpg",$filename2))$uploadimage2 = "<img src=".$_zb_url.$filename2." border=0 align=left><br>"; else $uploadimage2="";
                        $memo = autolink($uploadimage1.$uploadimage2.$memo);
                        if($data[ismember]) {
                                $imageBoxPattern = "/\\[img\\:(.+?)\\.(jpg|gif)\\,align\\=([a-z]){0,}\\,width\\=([0-9]+)\\,height\\=([0-9]+)\\,vspace\\=([0-9]+)\\,hspace\\=([0-9]+)\\,border\\=([0-9]+)\\]/i";
                                $memo=preg_replace($imageBoxPattern,"<img src='".$_zb_url."icon/member_image_box/$data[ismember]/\\\\1.\\\\2' align='\\\\3' width='\\\\4' height='\\\\5' vspace='\\\\6' hspace='\\\\7' border='\\\\8'>", stripslashes($memo));
                        }
                        $subject = cut_str(stripslashes($data[subject]),$textlen)."</font></b>";
                        $date = date($datetype, $data[reg_date]);
                        $header = str_replace("[notice_memo]",$memo,$header);
                        $header = str_replace("[notice_subject]",$subject,$header);
                        $header = str_replace("[notice_date]",$date,$header);
                }

                $main_data = "";
                while($data=mysql_fetch_array($result)) {
                        $name = stripslashes($data[name]);
                        $subject = cut_str(stripslashes($data[subject]),$textlen)."</font></b>";
                        $date = date($datetype, $data[reg_date]);
                        $more_img = $_zb_url."latest_skin/$skinname/images/more.gif"; // more 추가부분
                       
                        if($data[total_comment]) $comment = "[".$data[total_comment]."]"; else $comment="";

                        $main = $loop;
                        $main = str_replace("[name]",$name,$main);
                        $main = str_replace("[date]",$date,$main);
                        $main = str_replace("[subject]","<a href='".$_zb_url.$target."&no=$data[no]'>".$subject."</a>",$main);
                        $main = str_replace("[comment]",$comment,$main);
                        $main_data .= "\\n".$main;
                }
                $list = $header.$main_data.$footer;
                $list = str_replace("[title]","<a href='".$_zb_url."zboard.php?id=".$id."'>".$title."</a>",$list);
                $list = str_replace("[more]","<a href='".$_zb_url."zboard.php?id=".$id."' target='_self'>"."<span style=font-size:9pt;>[ 나머지도 보자! ]</span>"."</a>",$list); // more 추가부분               
                $list = str_replace("[dir]",$_zb_url."latest_skin/".$skinname."/images/",$list);

                echo $list;
        }

//---------------- 여기까지 복사하신후
새로운 편집창을 하나 띄우신다음 붙여넣기 하세요

        // 최근 글 목록 (일반 게시판 형)
        function print_bbs

이부분을

  //Best글 목록
  function print_best

이렇게 바꿔 주세요

$result = mysql_query("select * from $t_board"."_$id where is_secret=0 order by no desc limit $num", $connect) or die(mysql_error());

이부분을 찾아서
조회수로 추출할경우
$result=mysql_query("select * from zetyx_board"."_$id where reg_date > $start_date and reg_date < $end_date and headnum > -2000000000 and depth = '0' order by hit desc limit $num", $connect) or die(mysql_error());

추천수로 추출할경우
$result=mysql_query("select * from zetyx_board"."_$id where reg_date > $start_date and reg_date < $end_date and headnum > -2000000000 and depth = '0' order by vote desc limit $num", $connect) or die(mysql_error());

다음은...

while($data=mysql_fetch_array($result)) {
$name = stripslashes($data[name]);
$subject = cut_str(stripslashes($data[subject]),$textlen)."</font></b>";
$date = date($datetype, $data[reg_date]);
if($data[total_comment]) $comment = "[".$data[total_comment]."]"; else $comment="";

이부분이 있을겁니다. 여기서 $subject = cut_str(stripslashes($data[subject]),$textlen)."</font></b>"; 라인 밑에

$hit = stripslashes($data[hit]);
$vote = stripslashes($data[vote]);

이걸 삽입해주세요.

바로 아래에 보면 다음과 같은 부분이 나올겁니다.

$main = $loop;
$main = str_replace("[name]",$name,$main);
$main = str_replace("[date]",$date,$main);
$main = str_replace("[subject]","<a href='".$_zb_url.$target."&no=$data[no]'>".$subject."</a>",$main);
$main = str_replace("[comment]",$comment,$main);
$main = str_replace("[category]",$category,$main);
$main_data .= "\\n".$main;

$main = str_replace("[date]",$date,$main); 이줄 아래에 다음과 같이 삽입해주세요.

$main = str_replace("[hit]",$hit,$main);
$main = str_replace("[vote]",$vote,$main);

---------------------------------------------------------------------

잠시 쉬시구요 ^^

        global $_zb_path, $_zb_url, $connect, $t_board, $admin_table;

위에 줄을 찾으세요
찾으신후 바로 아래줄에 다음을 삽입해 주세요.

//날자와 달을 지정하는 변수 정의
  $now = time();    // 현재 시간을 초단위로 구합니다.  time()사용하면 유니버설스템프타임 구해줍니다
  $year= date('Y'); //현재의 연도를 구해줍니다 (2004 이런식으로) 나중에 테이블의 제목에 사용하게 됩니다
  $month= date('m'); //현재의 달을 구합니다. ( 07 이런식입니다. 여기서 0 을 빼고 싶은데 이것 까지는 모르겠습니다.
  $day=date('d');  // 오늘 날자를 구합니다.
  $hour = date('H');  // 지금 몇시인지 구해줍니다. h는 12시간으로 표기 H는 24시간으로 표기해주네요
  $min = date('i');    // 지금 몇분인지 구해줍니다. 
  $sec = date('s');    // 현재 몇초인지 구해줍니다.
  $to_day = mktime(0,0,0,$month,$day,$year); //지정된 날짜의 시간을 초단위로 구해줍니다./
  $end_day=date('t');  // 이달의 마지막날.


$result=mysql_query("select * from zetyx_board"."_$id where reg_date > $start_date and reg_date < $end_date and headnum > -2000000000 and depth = '0' order by hit desc limit $num",$connect) or die(mysql_error());
위의 부분을 찾으세요.
위의 부분 바로 윗줄에 다음을 삽입해 주세요.

    //이부분이 허접하지만 날짜별로 뽑아올수 있게 해주는 부분입니다.
    if(($day >= 1)&&($day <= 10)) {
    $start_date = mktime(0,0,0,$month,1,$year); // 매월 1일을 구함. 이건 숫자로 바꾼것입니다.
    $end_date = mktime(0,0,0,$month,10,$year); //매월 10일을 구함. 이것 역시 숫자로 바꾸어 주었습니다.   
    } elseif(($day >= 11)&&($day <= 20)) {
    $start_date = mktime(0,0,0,$month,11,$year); // 매월 11일을 구함. 이건 숫자로 바꾼것입니다.
    $end_date = mktime(0,0,0,$month,20,$year); //매월 20일을 구함. 이것 역시 숫자로 바꾸어 주었습니다.
    } elseif(($day >= 21)&&($day <= 31)) {
    $start_date = mktime(0,0,0,$month,21,$year); // 매월 21일을 구함. 이건 숫자로 바꾼것입니다.
    $end_date = mktime(0,0,0,$month,$end_day,$year); //매월 마지막날을 구함. 이것 역시 숫자로 바꾸어 주었습니다.
    } else {
    }

여기까지 수정하신내용을 전체선택하셔서

outlogin.php 파일의
        // 최근 글 목록 (일반 게시판 형)
        function print_bbs($skinname, $title, $id, $num=5, $textlen=30, $datetype="Y/m/d") {
       
이부분 찾으셨으면

  // 최근 글 목록 (일반 게시판 형)   

이부분 바로 위에다 붙혀넣기 하세요.

--------------------------------------------------
아래부분부터는 제가 사용하고 있는 그대로 입니다.
개개인의 필요에 맞게 고쳐서 쓰세요.

이제 Best 게시물을 추출하려고 하는 스킨 폴더의 list_head.php 파일을 불러옵니다.

list_head.php 제일 마지막 줄에 다음을 삽입합니다.


<? if($member[no]){ ?>      //제가 실력이 딸려서 로그인 했을때와 안했을때 나오는 화면이 조금 다르더군요 ㅡㅡ;
<? print_best("default/comma_bbs33", "homepr", "homepr", 3, 500)?>  //로그인했을때 보여지는 스킨
<? } else { ?>
<? print_best("default/comma_bbs22", "homepr", "homepr", 3, 500)?>  //로그인 안했을때 보여지는 스킨
<? } ?>

이제 latest_skin 은 직접 만드셔야 하는데
제가 사용하는 소스 적어놓겠습니다.

// default/comma_bbs33 스킨
<style type="text/css">
td,table,body,blockquote,div,p {font-family:굴림}

a:link {text-decoration:none; color:#146D82}
a:visited {text-decoration:none; color:#146D82}
a:hover {text-decoration:none; color:#7DCDE0}
</style>
[loop]
<tr height="25" align=center bgcolor="#DFF9FF" onMouseOver=this.style.backgroundColor='' onMouseOut=this.style.backgroundColor=''>

  <?=$hide_cart_start?><td width=10 valign="middle" background="<?=$dir?>/list_head_bg.gif"></td><?=$hide_cart_end?>
 
  <td width=30 background="<?=$dir?>/dot.gif" nowrap><font color="#008FC4">Best</font></td>

  <td width=100% background="<?=$dir?>/dot.gif" align=left style='word-break:break-all;'>  <b>[subject]</b> <font style="font-size:7pt; color:#8CA905; font-family:verdana">[comment]</font></td>

  <td width=100 background="<?=$dir?>/dot.gif" nowrap> <font face="굴림" color="#666666">[name]</font> </td>

  <td width=60 background="<?=$dir?>/dot.gif" nowrap>[date]</td>

  <td width=30 background="<?=$dir?>/dot.gif" nowrap>[hit]</td>
 
  <td width=30 background="<?=$dir?>/dot.gif" nowrap>[vote]</td>
</tr>
[/loop]

// default/comma_bbs22 스킨
<style type="text/css">
td,table,body,blockquote,div,p {font-family:굴림}

a:link {text-decoration:none; color:#146D82}
a:visited {text-decoration:none; color:#146D82}
a:hover {text-decoration:none; color:#7DCDE0}
</style>
[loop]
<tr height="25" align=center bgcolor="#DFF9FF" onMouseOver=this.style.backgroundColor='' onMouseOut=this.style.backgroundColor=''>

  <td width=30 background="<?=$dir?>/dot.gif" nowrap><font color="#008FC4">Best</font></td>

  <td width=100% background="<?=$dir?>/dot.gif" align=left style='word-break:break-all;'>  <b>[subject]</b> <font style="font-size:7pt; color:#8CA905; font-family:verdana">[comment]</font></td>

  <td width=100 background="<?=$dir?>/dot.gif" nowrap> <font face="굴림" color="#666666">[name]</font> </td>

  <td width=60 background="<?=$dir?>/dot.gif" nowrap>[date]</td>

  <td width=30 background="<?=$dir?>/dot.gif" nowrap>[hit]</td>
 
  <td width=30 background="<?=$dir?>/dot.gif" nowrap>[vote]</td>
</tr>
[/loop]

---------------------------------------------------------------------

여기 까지 입니다..
시원찮은 실력으로 하다보니 소스도 길어지고,, 암튼 많이 복잡하기도 하죠 ㅡㅡ;

위에 소스가 더간략해질수 있다면 좋을것 같은데.. 글세요 저는 잘 ......

필요한분은 유용하게 쓰시길.....

Share Post:

댓글목록

등록된 댓글이 없습니다.

Sign In
OR
Don't have an account? SIGN UP

Keywords

Visits

접속자

Total Visits
1,892,168