PHP 프로그래밍

본문 바로가기
사이트 내 전체검색


Web Programming >> PHP Programming
[목차]
제3장 PHP에서 꼭 알아두어야 할 함수

    2. 달력만들기

달력만들기 달력을 단계별로 만들어 보았다.
1단계 : 달력 틀 만들기(1)

<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p align="center"><b>2001년 5월</b></p>
<table align="center" border="1" width="464">
    <tr>
        <td width="60" height="34">
            <p align="center">일</p>
        </td>
        <td width="60" height="34">
            <p align="center">월</p>
        </td>
        <td width="60" height="34">
            <p align="center">화</p>
        </td>
        <td width="60" height="34">
            <p align="center">수</p>
        </td>
        <td width="60" height="34">
            <p align="center">목</p>
        </td>
        <td width="60" height="34">
            <p align="center">금</p>
        </td>
        <td width="58" height="34">
            <p align="center">토</p>
        </td>
    </tr>
    <tr>
	    <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
	</tr>
	<tr>
	    <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
	</tr>
	<tr>
	    <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
	</tr>
	<tr> 
	    <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
	</tr>
	<tr>  
	    <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
	</tr>
	<tr>     
	    <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
        <td width="60" height="34">
            <p align="center">&nbsp;</p>
        </td>
	</tr>
	</table>
<p>&nbsp;</p>
</body>

</html>

2단계 : 달력 틀 만들기(2)

for 문을 이용하여 반복부분을 처리함.

 
<?
$year = 2001;
$mon = 5;
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p align="center"><b><?echo($year);?>년 <?echo($mon);?>월</b></p>
<table align="center" border="1" width="464">
    <tr>
        <td width="60" height="34">
            <p align="center">일</p>
        </td>
        <td width="60" height="34">
            <p align="center">월</p>
        </td>
        <td width="60" height="34">
            <p align="center">화</p>
        </td>
        <td width="60" height="34">
            <p align="center">수</p>
        </td>
        <td width="60" height="34">
            <p align="center">목</p>
        </td>
        <td width="60" height="34">
            <p align="center">금</p>
        </td>
        <td width="58" height="34">
            <p align="center">토</p>
        </td>
    </tr>
<?
for($i=0;$i<=5;$i++) {
	echo("<tr>");
	for($j=0;$j<7;$j++) {
?>
        <td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
	}
	echo("	</tr>");
}
?>
</table>
<p> </p>
</body>

</html>

 
3단계 : 날짜 넣기
<?
$year = 2001;
$mon = 5;
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p align="center"><b><?echo($year);?>년 <?echo($mon);?>월</b></p>
<table align="center" border="1" width="464">
    <tr>
        <td width="60" height="34">
            <p align="center">일</p>
        </td>
        <td width="60" height="34">
            <p align="center">월</p>
        </td>
        <td width="60" height="34">
            <p align="center">화</p>
        </td>
        <td width="60" height="34">
            <p align="center">수</p>
        </td>
        <td width="60" height="34">
            <p align="center">목</p>
        </td>
        <td width="60" height="34">
            <p align="center">금</p>
        </td>
        <td width="58" height="34">
            <p align="center">토</p>
        </td>
    </tr>
<?
$k=1;
for($i=0;$i<=5;$i++) {
	echo("<tr>");
	for($j=0;$j<7;$j++) {
		if($k <= 30) {
?>
        <td width="60" height="34">
            <p align="center"><?echo($k);?></p>
        </td>
<?
			$k++;
		}
		else {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
	}
	echo("	</tr>");
}
?>
</table>
<p> </p>
</body>

</html>


 
4단계 : 그 달의 시작일과 종료일 처리하기
<?
$year = 2001;
$mon = 6;
$startday = date("w",mktime(0,0,0,$mon,1,$year));
$endday = date("t",mktime(0,0,0,$mon,1,$year));
// echo("$startday    $endday");
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p align="center"><b><?echo($year);?>년 <?echo($mon);?>월</b></p>
<table align="center" border="1" width="464">
    <tr>
        <td width="60" height="34">
            <p align="center">일</p>
        </td>
        <td width="60" height="34">
            <p align="center">월</p>
        </td>
        <td width="60" height="34">
            <p align="center">화</p>
        </td>
        <td width="60" height="34">
            <p align="center">수</p>
        </td>
        <td width="60" height="34">
            <p align="center">목</p>
        </td>
        <td width="60" height="34">
            <p align="center">금</p>
        </td>
        <td width="58" height="34">
            <p align="center">토</p>
        </td>
    </tr>
<?
$k=1;
for($i=0;$i<=5;$i++) {
	echo("<tr>");
	for($j=0;$j<7;$j++) {
		if($i == 0 && $j < $startday) {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
		else if($k <= $endday) {
?>
        <td width="60" height="34">
            <p align="center"><?echo($k);?></p>
        </td>
<?
			$k++;
		}
		else {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
	}
	echo("	</tr>");
}
?>
</table>
<p> </p>
</body>

</html>

 
5단계 : 폼테그로 년월을 입력받기 

 
<?
if($mode != "form") {
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<B>달력만들기</B>
<FORM METHOD=POST ACTION="">
<INPUT TYPE="hidden" name="mode" value="form">
<INPUT TYPE="text" NAME="year">년 <SELECT NAME="mon">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
</SELECT> 월
<INPUT TYPE="submit" value="달력 만들기">
</FORM>
</body>
</html>
<?
}
else {

//$year = 2001;
//$mon = 6;
$startday = date("w",mktime(0,0,0,$mon,1,$year));
$endday = date("t",mktime(0,0,0,$mon,1,$year));
// echo("$startday    $endday");
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p align="center"><b><?echo($year);?>년 <?echo($mon);?>월</b></p>
<table align="center" border="1" width="464">
    <tr>
        <td width="60" height="34">
            <p align="center">일</p>
        </td>
        <td width="60" height="34">
            <p align="center">월</p>
        </td>
        <td width="60" height="34">
            <p align="center">화</p>
        </td>
        <td width="60" height="34">
            <p align="center">수</p>
        </td>
        <td width="60" height="34">
            <p align="center">목</p>
        </td>
        <td width="60" height="34">
            <p align="center">금</p>
        </td>
        <td width="58" height="34">
            <p align="center">토</p>
        </td>
    </tr>
<?
$k=1;
for($i=0;$i<=5;$i++) {
	echo("<tr>");
	for($j=0;$j<7;$j++) {
		if($i == 0 && $j < $startday) {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
		else if($k <= $endday) {
?>
        <td width="60" height="34">
            <p align="center"><?echo($k);?></p>
        </td>
<?
			$k++;
		}
		else {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
	}
	echo("	</tr>");
}
?>
</table>
<P>
<CENTER><A HREF="cal_4.html"><FONT SIZE="2" COLOR="">다시 만들기</FONT></A></CENTER>
</body>

</html>
<?
}
?>


6단계 : 달력의 마지막줄이 날짜가 없을 때, 출력되지 않게 하시오

예) 2001년 9월과 2001년 6월을 입력하면, 2001년 6월의 경우는 마지막 줄이 빈줄로
보인다. 이부분이 나타나지 않게 하면 된다.



5단계 : 폼테그로 년월을 입력받기 


<?
if($mode != "form") {
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<B>달력만들기</B>
<FORM METHOD=POST ACTION="">
<INPUT TYPE="hidden" name="mode" value="form">
<INPUT TYPE="text" NAME="year">년 <SELECT NAME="mon">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
</SELECT> 월
<INPUT TYPE="submit" value="달력 만들기">
</FORM>
</body>
</html>
<?
}
else {

//$year = 2001;
//$mon = 6;
$startday = date("w",mktime(0,0,0,$mon,1,$year));
$endday = date("t",mktime(0,0,0,$mon,1,$year));
// echo("$startday    $endday");
?>
<html>

<head>
<title>달력만들기</title>
<meta name="generator" content="Namo WebEditor v4.0">
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<p align="center"><b><?echo($year);?>년 <?echo($mon);?>월</b></p>
<table align="center" border="1" width="464">
    <tr>
        <td width="60" height="34">
            <p align="center">일</p>
        </td>
        <td width="60" height="34">
            <p align="center">월</p>
        </td>
        <td width="60" height="34">
            <p align="center">화</p>
        </td>
        <td width="60" height="34">
            <p align="center">수</p>
        </td>
        <td width="60" height="34">
            <p align="center">목</p>
        </td>
        <td width="60" height="34">
            <p align="center">금</p>
        </td>
        <td width="58" height="34">
            <p align="center">토</p>
        </td>
    </tr>
<?
$k=1;
for($i=0;$i<=5;$i++) {
	echo("<tr>");
	for($j=0;$j<7;$j++) {
		if($i == 0 && $j < $startday) {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
		else if($k <= $endday) {
?>
        <td width="60" height="34">
            <p align="center"><?echo($k);?></p>
        </td>
<?
			$k++;
		}
		else {
?>
		<td width="60" height="34">
            <p align="center"> </p>
        </td>
<?
		}
	}
	echo("	</tr>");
}
?>
</table>
<P>
<CENTER><A HREF="cal_4.html"><FONT SIZE="2" COLOR="">다시 만들기</FONT></A></CENTER>
</body>

</html>
<?
}
?>


6단계 : 달력의 마지막줄이 날짜가 없을 때, 출력되지 않게 하시오

예) 2001년 9월과 2001년 6월을 입력하면, 2001년 6월의 경우는 마지막 줄이 빈줄로
보인다. 이부분이 나타나지 않게 하면 된다.


 
[목차]

개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.