สร้างปฏิทินด้วย php และ css โดยไม่ต้องใฃ้ตาราง

Bookmark and Share

สร้างปฏิทินด้วย php และ css โดยไม่ต้องใฃ้ตาราง

CSS Code
 

<style type="text/css">
div.holder{
	position:relative;
	font-family:tahoma, "Microsoft Sans Serif", Vanessa;
	border:2px solid #999;
	float:left;
	font-size:12px;
	width:175px;
	padding:5px;
}
div.month{
	position:relative;
	display:block;
	height:18px;
	width:100%;
	float:left;
	left:0;
	top:0;
	background:#567; 
	color:#fff; 
	border-bottom:2px solid #89a;
	text-align:center;
}
div.wkday{
	position:relative;
	clear:both;
	float:left;
	height:18px;
	display:block;
	width:100%;
	background:#567; 
	color:#fff; 
	border-bottom:3px solid #234;
}
div.wkday span{
	display:block;
	float:left;
	width:25px;
	text-align:center;	
}
div.box_day {
	position:relative;
	width:100%;
	clear:both;
	float:left;	
	background:#EEEEEE; 
	color:#000;
	word-spacing:8px;
	text-indent:3px;
	}
</style>

PHP Code

<?php
$thai_month_arr=array(   
    "0"=>"",   
    "1"=>"มกราคม",   
    "2"=>"กุมภาพันธ์",   
    "3"=>"มีนาคม",   
    "4"=>"เมษายน",   
    "5"=>"พฤษภาคม",   
    "6"=>"มิถุนายน",    
    "7"=>"กรกฎาคม",   
    "8"=>"สิงหาคม",   
    "9"=>"กันยายน",   
    "10"=>"ตุลาคม",   
    "11"=>"พฤศจิกายน",   
    "12"=>"ธันวาคม"                     
);
//$now_month="2008-11-01";
$now_month=date("Y-m-01");
$mk_time=strtotime($now_month);
$day_no=date("t",$mk_time);
$wan_no=date("w",$mk_time);
$box_day=$day_no+$wan_no;
$rows_week=ceil($box_day/7);
$total_box=$rows_week*7;
function get_day($no_day,$wan_no,$day_no){
	$wan_tee=$no_day-$wan_no;
	if($wan_tee<=0){
		$wan_tee="__";						
		return $wan_tee;
	}else{
		if($wan_tee<=$day_no){
		return str_pad($wan_tee,2,"0",STR_PAD_LEFT);
		}else{
		return "__";
		}
	}
}
?>
<div class="holder">
<div class="month">
<?=$thai_month_arr[intval(date("m"))]?> <?=date("Y")+543?>
</div>
<div class="wkday">
<span>อา</span>
<span>จ</span>
<span>อ</span>
<span>พ</span>
<span>พฤ</span>
<span>ศ</span>
<span>ส</span>
</div>
<?php for($i=1;$i<=$total_box;$i++){ ?>
<?php if($i%7==1){ echo "<div class='box_day'>"; }?>
  <?=get_day($i,$wan_no,$day_no)?>
<?php if($i%7==0 || $i==$total_box){ echo "</div>n"; }?>
<?php } ?>
</div>
<br style="clear:both;" />

ตัวอย่าง
 


 

กรกฎาคม 2553
อา พฤ
__ __ __ __ 01 02 03
04 05 06 07 08 09 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31




บทความในหมวดที่่น่าสนใจ อื่นๆ PHP Learning

17 Oct 08 แสดงตัวอย่างรูป ก่อน upload image preview berfore upload อ่าน 3254 21 Oct 08 php กับการแสดงวันที่เป็นภาษาไทย อ่าน 3185 26 Mar 09 ฟังก์ชัน php แบ่งหน้าแต่งด้วย css อ่าน 2594 25 Sep 08 แบ่งหน้า ด้วย Code แบบง่าย อ่าน 2505 25 Sep 08 ดึงข้อมูลจากฐานข้อมูลใส่ List Box อ่าน 2372 25 Sep 08 ปฏิทินอย่างง่ายด้วย php และ css อ่าน 2300 25 Sep 08 การแสดงข้อมูลจากตารางด้วย PHP อ่าน 2109 25 Oct 08 ส่งอีเมลล์พร้อมกับแนบไฟล์ด้วย php mail function ได้อย่างง่าย อ่าน 2047 25 Sep 08 การสร้างวันเวลาปัจจุบัน ด้วยฟังก์ชัน date() อ่าน 1881 31 Mar 09 ดึงข้อมูลจากฐานข้อมูลเป็น excel ด้วย php รองรับภาษาไทย อ่าน 1857 25 Sep 08 ใช้ PHP สร้าง Javascript อย่างง่าย อ่าน 1842 14 Feb 09 คำนวณหาอายุ จากวันเกิด ด้วย php อ่าน 1835 25 Sep 08 Upload รูปภาพ หรือไฟล์ด้วย ฟังก์ชั่น ใช้ง่าย อ่าน 1817 30 Oct 08 ฟังก์ชันตรวจสอบอีเมลล์ ด้วย php ละเอียดมากขึ้น php check verify email อ่าน 1780 17 Mar 09 ง่ายๆ กับการส่งค่าตัวแปร PHP ไปใช้ใน Javascript อ่าน 1739
จำนวนผู้เยี่ยมชม 157924 คน 2010 © Copyright ninenik.com. All rights reserved.