简单的日历小帐本
此代码仅供参考:哦也:[code]<?php
$y = date('Y',time());
$m = date('m',time());
$d = date('d',time());
if (!$_GET['Y'] || !$_GET['M'] || !$_GET['D']){
header("Location:?Y=$y&M=$m&D=$d");
}
$Ynian = array(31,28,31,30,31,30,31,31,30,31,30,31);# 润年
$Nnian = array(31,29,31,30,31,30,31,31,30,31,30,31);# 不是润年
$Dweek = array('日','一','二','三','四','五','六');# 星期
$DayOfMonth = ($y%4==0 && $y%100!=0) || $y%400==0 ? $Nnian[$m-1] : $Ynian[$m-1];
$get_week = date('w',strtotime($y*100+$_GET['M'].'01'));# 得到月的第一天
require_once('db.php');
$db = new oDatabase('localhost','root','','calender');
?>
<meta http-equiv='Content-Type' content="text/html;charset=gb2312">
<title>@^_^@日历小帐本@^_^@</title>
<style type="text/css">
body {background:#666;}
.table1 td {width:100px;font-size:14px;text-align:center;background:#ccc;color:#fff;}
.table2 td {width:100px;font-size:18px;text-align:center;background:#ccc;font-family:'verdana';}
a {text-decoration:none;}
a:hover {text-decoration:underline;}
</style>
<table>
<tr>
<td width='340' valign='top' align='center' bgcolor='#ffffff'><br><img src="images/jj.jpg" width="320" height="240" alt="二口子" />
<p><a href="?Y=<?=$_GET['Y']?>&M=<?=$_GET['M']?>&D=<?=$_GET['D']?>" style='color:#ff7300;font-size:14px;'>^_^ [日历小帐本] ^_^</a></p></td>
<td valign='top' align='center' bgcolor='#ffffff'>
<table class='table1' border='0' cellspacing="1" cellpadding="0">
<tr><? for($i=0;$i<7;$i++){
echo "<td height='50'>星期$Dweek[$i]</td>";
}
?></tr>
</table>
<table class='table2' border='0' cellspacing="1" cellpadding="0">
<tr><? for($i=0;$i<$get_week;$i++){
echo "<td height='50'> </td>";
}
for($i=1;$i<=$DayOfMonth;$i++){
if($i<$d){
echo "<td height='50'><a href='?A=see&Y=$_GET[Y]&M=$_GET[M]&D=$_GET[D]&I=$i' title='查看'><font color='#ffffff'>$i</font></a></td>";
}elseif($i==$d){
echo "<td style='background:#ff7300;color:#fff;' height='50'><a href='?A=see&Y=$_GET[Y]&M=$_GET[M]&D=$_GET[D]&I=$i' title='查看'><font color='#ffffff'>$i</a> <a href='?A=add&Y=$_GET[Y]&M=$_GET[M]&D=$_GET[D]&I=$i' title='添加'>+</a></td>";
}else{
echo "<td height='50'><font color='#ffffff'>$i</font></td>";
}
if(($i+$get_week)%7==0&&$i!=$DayOfMonth) echo '</tr><tr>';
}
for($i--;($i+$get_week)%7!=0;$i++){
echo "<td height='50'> </td>";
}
?></tr>
</table>
<?
$Q1 = $db->query("select sum(price) from data where dateline like binary '%".$_GET['Y'].'-'.$_GET['M']."%'");
$c1 = $db->fetch_array($Q1);
$c1 = array_values($c1);
$c1 = $c1[0];
?>
<table border='0' cellspacing="0" cellpadding="0" align='right'><tr><td align='right' height='25'><span style='font-size:12px;color:red;'>本月共花了:<?=$c1?>元</span></td></tr></table><br>
<?
if($_GET['A']=='see'){
$query = $db->query("select * from data where dateline='".$_GET['Y']."-".$_GET['M']."-".$_GET['I']."'",$db);
while($rt = $db->fetch_array($query)) $t[] = $rt;
if($t){
?>
<table border='0' cellspacing="1" cellpadding="0" width='100%' style='font-size:12px;'>
<tr>
<td><?
foreach($t as $k=>$v){
echo ' 今天共花了:'.$v['marks'].$v['price'].'元<br>';
}
?></td>
</tr>
</table>
<? }} ?>
<? if($_GET['A']=='add'){ ?>
<form method='post' action='index.php?<? echo "Y=$y&M=$m&D=$d"; ?>' style='margin:0px;' name='myform' onsubmit='return ck();'>
<input type="hidden" name="A" value='save'/>
<table border='0' cellspacing="1" cellpadding="0" bgcolor='#ffffff' width='100%' style='font-size:14px;'>
<tr>
<td height='25'> 花了多少:<input type="text" name="price" /> 元</td>
</tr>
<tr>
<td height='25'> 买了什么:<textarea name="marks" rows="6" cols="60" style='vertical-align:bottom;'></textarea></td>
</tr>
<tr>
<td height='25' style='padding-left:84px;'><input type="submit" value='提 交'/></td>
</tr>
</table>
</form>
<script type="text/javascript">
<!--
function ck(){
if(document.myform.price.value==''){
alert('花了多少钱呀?');
document.myform.price.focus();
return false;
}
/*if(document.myform.marks.value==''){
alert('都买了些什么呀?');
document.myform.marks.focus();
return false;
}*/
}
//-->
</script>
<? } ?>
</td>
</tr>
</table>
<?
if($_POST['A']=='save'){
$db->query("insert into data (price,marks,dateline) values ('$_POST[price]','$_POST[marks]','$y-$m-$d')",$db);
echo "<meta http-equiv='refresh' content='0;url=index.php' />";
}
?>[/code] 收下!
页:
[1]