본문 바로가기

study

글번호 들어있는 php게시판 리스트

 <?
$title = "공지사항";
$mn = 8;
$sn = 1;
$cn = 0;




?>
<? include "../include/head.php" ?>
</head>
<body>
<!-- wrap -->
<div id="wrap" class="sub">
	<? include "../include/top.php" ?>
	 <!-- main -->
        <main id="main">
            <!-- sub_visual -->
            <div style="position:relative;width:100%;background:none;margin:0 auto;max-width:1920px;text-align:center;">
                <img src="/images/event/event_01.png" alt="" style="width:100%;">
                <img src="/images/event/event_02.png" alt="" style="width:100%;">
                <img src="/images/event/event_03.png" alt="" style="width:100%;">
                <img src="/images/event/event_04.png" alt="" style="width:100%;">
                <img src="/images/event/event_05.png" alt="" style="width:100%;cursor:pointer" id="event_click">
                <img src="/images/event/event_06.png" alt="" style="width:100%;">
            </div>
            <!-- //sub_visual -->



            <!-- sub_contents -->
            <div class="board_wrap" style="background:#fff;width:100%;margin:0 auto;max-width:1920px;text-align:center;">
                <a name="table1"></a>
                <img src="/images/event/event_07.png" style="padding:73px;padding-top:0px;cursor:pointer" onclick="fn_alert()" id="event_go"><br />
                <img src="/images/event/event_08.png" alt="" style"width:100%">
                <img src="/images/event/event_09.png" alt="" style="width:100%;display:none">
            <?php
            //게시판 목록보기에 필요한 각종 변수 초기값을 설정합니다.
            $tablename="tbl_event"; //테이블 이름
            if($page == '') $page = 1; //페이지 번호가 없으면 1

            if($stx){
                $sqry = " where subject like '%$stx%'";
            }

            $list_num = 10; //한 페이지에 보여줄 목록 갯수
            $page_num = 10; //한 화면에 보여줄 페이지 링크(묶음) 갯수
            $offset = $list_num*($page-1); //한 페이지의 시작 글 번호(listnum 수만큼 나누었을 때 시작하는 글의 번호)

            //전체 글 수를 구합니다. (쿼리문을 사용하여 결과를 배열로 저장하는 일반적 인 방법)
            $query="select count(*) as cnt from $tablename $sqry"; // SQL 쿼리문을 문자열 변수에 일단 저장하고

            $row=sql_fetch($query); //위 결과 값을 하나하나 배열로 저장합니다 .
            $total_no=$row['cnt']; //배열의 첫번째 요소의 값, 즉 테이블의 전체 글 수를 저장합니다.

            //전체 페이지 수와 현재 글 번호를 구합니다.
            $total_page=ceil($total_no/$list_num); // 전체글수를 페이지당글수로 나눈 값의 올림 값을 구합니다.
            $cur_num=$total_no - $list_num*($page-1); //현재 글번호

            //bbs테이블에서 목록을 가져옵니다. (위의 쿼리문 사용예와 비슷합니다 .)
            $query="select * from $tablename $sqry order by idx desc limit $offset, $list_num"; // SQL 쿼리문
            $result=sql_query($query);// or die (mysql_error()); // 쿼리문을 실행 결과
            //쿼리 결과를 하나씩 불러와 실제 HTML에 나타내는 것은 HTML 문 중간에 삽입합니다.

function cut_str2($str, $len, $suffix="…")
{
    $arr_str = preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
    $str_len = count($arr_str);

    if ($str_len >= $len) {
        $slice_str = array_slice($arr_str, 0, $len);
        $str = join("", $slice_str);

        return $str . ($str_len > $len ? $suffix : '');
    } else {
        $str = join("", $arr_str);
        return $str;
    }
}


            ?>
                <table class="form1">
				<colgroup>
					<col width="10%" />
					<col />
					<col width="20%" />
				</colgroup>
                    <tr>
                        <th class='title1'>번호</th>
                        <th class='title1'>제목</th>

                        <th class='title1'>날짜</th>
                    </tr>
                    <?php
                    $k=0;
					$a=0;
                    while($row=sql_fetch_array($result)){
						$a = $k+1;
                        $subject = $row['subject'];
                        if($stx){
                            $subject = str_replace($stx,"<span class='red'>$stx</span>",$subject);
                        }
						$subject=cut_str2($subject,20);
                    ?>
                     <tr>
                        <td class='cont1'><?
						$buyNum =$total_no-($page_num*($page-1));
						$Num = $buyNum - $k;
						echo $Num;

						?></td>
                        <td class='cont1 alignleft'>
                            <?php
								echo $_SESSION["ss_id"];
                                if($_SESSION["ss_id"]=="admin"){
                                ?>
                                <a href="event_view.php?idx=<?=$row['idx']?>"><?=$subject?></a>
                                <?php
                                }else{
                                    echo $subject;
                                }
                            ?>

                        </td>
                        <td class='cont1'><?=substr($row['wdate'],2,8)?></td>

                    </tr>
                    <?php
                    $k=$k+1;
                    }

                    if($k==0){
                        if($stx){
                            echo "<tr><td align=center colspan='5' style='height:40px;line-height:40px'>검색 내용이 없습니다.</td></tr>";
                        }else{
                            echo "<tr><td align=center colspan='5'  style='height:40px;line-height:40px'>등록된 글이 없습니다.</td></tr>";
                        }
                    }

                    ?>

                    <?php
                    ?>
                </table>
                <div style="width:300px;margin:0 auto;text-align:center;margin-top:30px;" class="paging1">
                    <?
                        //여기서부터 각종 페이지 링크
                        //먼저, 한 화면에 보이는 블록($page_num 기본값 이상일 때 블록으로 나뉘어짐 )
                        $total_block=ceil($total_page/$page_num);


                        $block=ceil($page/$page_num); //현재 블록

                        $first=($block-1)*$page_num; // 페이지 블록이 시작하는 첫 페이지
                        $last=$block*$page_num; //페이지 블록의 끝 페이지

                        if($block >= $total_block) {
                                $last=$total_page;
                        }


                        //[처음][*개앞]
                        if($block > 1) {
                                $prev=$first-1;
                              //  echo "<a href='?page=1'>[처음 ]</a>&nbsp; ";
                                echo "<a href='?stx=$stx&page=$prev#table1'> &lt&lt </a>";
                        }else{
                                echo "<a > &lt&lt </a>";
                        }

                        //[이전]
                        if($page > 1) {
                                $go_page=$page-1;
                                echo "  <a href='?stx=$stx&page=$go_page#table1'>&nbsp;&lt;&nbsp;</a>&nbsp;       ";

                        }else{
                                echo "<a > &nbsp;&lt;&nbsp; </a>";
                        }


                        //페이지 링크
                        for ($page_link=$first+1;$page_link<=$last;$page_link++) {
                                if($page_link==$page) {
                                        echo "<a color=green class='nums'><b>$page_link</b></a>";
                                }
                                else {
                                        echo "<a href='?stx=$stx&page=$page_link#table1' class='nums2'>$page_link</a>";
                                }
                        }

                        //[다음]
                        if($total_page > $page) {
                                $go_page=$page+1;
                                echo "&nbsp;<a href='?stx=$stx&page=$go_page#table1'>&nbsp;&gt;&nbsp;</a>";
                        }else{
                                echo "&nbsp;<a >&nbsp;&gt;&nbsp;</a>";
                        }

                        //[*개뒤][마지막]
                        if($block < $total_block) {
                                $next=$last+1;
                                echo "<a href='?stx=$stx&page=$netxt#table1'>&nbsp;&gt;&gt;&nbsp;</a>&nbsp;";
                               // echo "<a href='?page=$total_page'>[마지막]</a>";
                        }else{
                                echo "<a >&nbsp;&gt;&gt;&nbsp;</a>&nbsp;";
                        }

                        ?>



                </div>
                <div style="border:1px solid #f0f0f0;margin:0 auto;text-align:center;width:100%;text-align:center;margin-top:50px">
                    <table style="text-align:center;margin:0 auto;">
                        <tr>
                            <td align=center style="text-align:center;background:#none">
                                <form method="post" name="qform" action="#table1">
                                    <input type="text" name="stx" value="<?=$stx?>">
                                     <input type="submit" value="검색" style="font-size: 16px;color: #585858;height: 35px;background:#e0e0e0;padding:0px 10px">
                                </form>

                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <!-- //sub_contents -->
        </main>
        <!-- //main -->
        <script>
            function fn_alert() {
                if (confirm('코골이 콘테스트 이벤트 참여시 개인정보활용에 동의해 주셔야 이벤트 참여가 가능합니다.')) {
                    window.location.href = './event_write.php';
                }
            }
            $(function() {
                $("#event_click").click(function() {

                    $('html, body').animate({
                        scrollTop: $("#event_go").offset().top - 200
                    }, 2000);
                })
            })

        </script>
	<? include "../include/footer.php" ?>

</div>

<style>

    .paging1 a{border:1px solid #909090;padding:5px;margin:2px;}
    table.form1{width:100%;margin:0 auto;border-bottom:4px solid #1D5386}
    th.title1{background:#1D5386;color:#fff;font-size:1em;font-weight:400;height:40px;line-height:40px;}
    td.cont1{background:#fff;color:#999;text-align:center;line-height:40px;height:40px;border-bottom:1px solid #f0f0f0}
    td.alignleft{text-align:left}
    a.nums{padding: 5px 10px;margin:2px;border:1px solid #ee0000;width:15px;box-sizing: border-box}
    a.nums2{padding: 5px 10px;margin:2px;width:15px;box-sizing: border-box}
</style>
<!-- //wrap -->
</body>
</html>