웹마스터 팁

군바리라..

2536 경교대 홈페이지를 관리하고 있습니다.

그런데 문득, 부대에서 생일자나 입대한지 1주년, 2주년 되었을 때를

홈페이지에 표시해 주는 기능이 있으면 좋지 않을까? 하는 생각이 들어,

바로 코딩에 들어가게 되었습니다.

여기저기서 보고 소스를 많이 참고하여 만들었습니다.

물론 데이터 입력폼, 리스트폼이 있어야 합니다.

데이터 베이스에 저장한 값으로는

이름 name
기수 th
생일 bira
입대일 ina
전역일 outa

입니다.

참고 : 원래 함수에 $num 값을 받아 갯수만큼ㅁ만 추출하려 했지만, 제대로 먹지를 않습니다.;;
         때문에 rday 값으로 그 일정 기간만큼만 추출해줍니다.


<?

//1주년 예정자.
function birthday($num, $rday){
        
        $today_t = mktime(0,0,0,date(m),date(d),date(Y)); //오늘의 타임스템프
        $rday_s = $rday * 24 * 60 * 60; //몇일후일지 초로 환산
        $total_t = $rday_s + $today_t + (60*60*24);  //today timestamp 값+ 몇일후 = 총 timestamp 값
        $query = "select * from date_table order by th";
        include "./date/dbconn.html";
        $result = mysql_query($query,$dbconn);
        $total_record = mysql_num_rows($result);
        $dc = '0'; //데이터카운터

        /*
        *
        *
        *
        1주년 및 생일 추출
        *
        *
        */
        

        /* 생일 추출 부분   */
        for ($i = 0;$i < $total_record;$i++){
                $data = mysql_fetch_array($result);
                
                $입대일 = date("Y-m-d",$data[ina]); //입대일을 date값으로 환산
                $입대일_배열 = explode("-",$입대일);
                $temp_y = date(Y)+1; //내년
                $입대일_t = mktime(23,57,0,$입대일_배열[1],$입대일_배열[2],date(Y)); //현재 "년도"의 입대일 월 일 의 timestamp 값을 구함
                $입대일_tnext = mktime(23,56,0,$입대일_배열[1],$입대일_배열[2],$temp_y); //다음 "년도"의 입대일 월 일 의 timestamp 값을 구함
                $일주년 = $입대일_배열[0] + 1;
                $이주년 = $입대일_배열[0] + 2;
                $생일 = date("Y-m-d",$data[bira]); //생일을 date값으로
                $생일_배열 = explode("-",$생일); //배열로 저장
                $생일_t = mktime(23,55,0,$생일_배열[1],$생일_배열[2],date(Y)); //생일의 월. 일의 현재년도의 값을 타입스템프로 저장.
                
                $생일_tnext = mktime(23,58,0,$생일_배열[1],$생일_배열[2],$temp_y); //생일의 월. 일의 다음년도의 값을 타입스템프로 저장.
                                        



        /* 1,2주년 추출  */
                if($data[outa] >= time()){  //출력할 범위 설정                //

                                if($today_t <= $입대일_t && $입대일_t <= $total_t){
                                        if ($일주년 == date(Y)){
                                                $mark[$dc] = '1주년';
                                                
                                        }
                                        else if($이주년 == date(Y)){
                                                $mark[$dc] = '2주년';
                                        }
                                        //echo "".$data[name]." ".$입대일_t." map : ".$map[$입대일_t]."
";

                                        $기념일[$dc] = $data;
                                        for ($i = 1;$i <= '10';$i++){
                                                if ($tm[$dc-$i] == $입대일_t){
                                                        $입대일_t++;
                                                }
                                        }
                                        
                                        //echo "".$data[name]." ".$입대일_t." map : ".$map[$입대일_t]."
";

                                        while ($map[$입대일_t]){
                                                $입대일_t++;
                                        }
                                        $tm[$dc]= $입대일_t;
                                        $map[$입대일_t] = $dc;
                                        $dc++;
                                        //echo "".$data[name]." ".$입대일_t." map : ".$map[$입대일_t]."
";
                                
                                        
                                }
                                if($today_t<= $입대일_tnext && $입대일_tnext <=$total_t ){
                                        if ($일주년 == $temp_y){
                                                $mark[$dc] = '1주년';
                                                
                                        }
                                        else if($이주년 == $temp_y){
                                                $mark[$dc] = '2주년'+ ';
                                        }
                                        
                                        $기념일[$dc] = $data;
                                        if ($tm[$dc-1] == $입대일_tnext){
                                                $입대일_tnext++;
                                        }

                                        while ($map[$입대일_tnext]){
                                                $입대일_tnext++;
                                        }
                                        $tm[$dc]= $입대일_tnext;
                                        $map[$입대일_tnext] = $dc;
                                        $dc++;
                                        
                                        
                                }

                                if($today_t <= $생일_t && $생일_t <= $total_t){
                                        $mark[$dc] = '생일';
                                        $기념일[$dc] = $data;
                                        for ($i=1;$i <= $dc;$i++){
                                                if ($tm[$dc-$i] == $생일_tnext){
                                                $생일_tnext++;
                                                }
                                        }
                                        $tm[$dc]= $생일_t;
                                        $map[$생일_t] = $dc;
                                        
                                        $dc++;

                                }
                                if($today_t <= $생일_tnext && $생일_tnext <= $total_t){
                                        $mark[$dc] = '생일';
                                        $기념일[$dc] = $data;
                                        for ($i=1;$i <= $dc;$i++){
                                                if ($tm[$dc-$i] == $생일_tnext){
                                                $생일_tnext++;
                                                }
                                        }
                                        //$micro = (double)microtime();
                                        //$생일_tnext = doubleval($생일_tnext);
                                        //$생일_tnext += $micro;
                                        //$tm[$dc] = doubleval($tm[$dc]);
                                        $tm[$dc]= $생일_tnext;
                                        $map[$생일_tnext] = $dc;                                        
                                        
                                        $dc++;        
                                        

                                }


                }
        }

        
        if ($dc){        //시간순 정렬
        sort($tm);
        }
/**********test form*********************
*
* $test_temp = implode(" = ",$tm);
* $test_temp1[0] = $map[$tm[0]];
* $test_temp1[1] = $map[$tm[1]];
* $test_temp1[2] = $map[$tm[2]];
* $temp = implode(" : ",$test_temp1);
* echo (" $test_temp
$temp
");
****************************************/
//출력부분

$today = date("m-d");
$outdate = date("m-d",$total_t);
$subject_n = "대원 1, 2주년 및 생일";
//생일자 및 1주년 2주년자 추출
        echo("
        <table cellpadding = 4>
        <tr>
                <td align = center bgcolor = '#6F86BC'>
                $subject_n

                $today ~ $outdate 까지

                </td>
        </tr>
        <tr>
                <td bgcolor = '#F0F0F0'>
        ");
        for($i = 0; $i < sizeof($tm) ; $i++){
                $n = $map[$tm[$i]];
                if ($mark[$n] == '생일'){
                        $출력일 = date("[m-d]", $기념일[$n][bira]);
                }
                else if ($mark[$n] == '1주년' || $mark[$n] == '2주년'){
                        $출력일 = date("[m-d]", $기념일[$n][ina]);
                }
                $p_th = $기념일[$n][th];
                $p_name = $기념일[$n][name];
                $p_mark = $mark[$n];
                $string = "".$출력일."".$기념일[$n][th]."".$기념일[$n][name]."-".$mark[$n]."";
                if (!$map){
                echo("
                        기간중 행사가 없습니다.

                ");
                }
                else{

                echo("
                        $string

                ");        
                }
        }
        echo("
                </td>
        </tr>
        </table>
        ");

}
?>


완성된 예제를 보시려면 http://ns2536.go.kr
왼쪽 하단을 보시면 됩니다.