<?php
//计算当月天数
$days=date('t',strtotime('2017-11-1'));
$w=date('w',strtotime('2017-11-1'));
$firstday=1-$w;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<center>
<h2>2017年11月</h2>
<table border='1px' width='700px' cellspacing="0">
<tr>
<th>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th>星期六</th>
</tr>
<?php
for($i=$firstday;$i<=$days;){
echo "<tr>";
for($j=1;$j<=7;$j++){
if($i<=0 || $i>$days){
echo "<td></td>";
}else{
echo "<td>{$i}</td>";
}
$i++;
}
echo "</tr>";
}
?>
</table>
</center>
</body>
</center>
</body>
</html>
以下部分是在tp框架中的应用
后端代码:
$param=$this->request->param();
$year=isset($param['y'])?$param['y']:date('Y');
//如果没有传入月份则获取当前系统月份
$month=isset($param['m'])?$param['m']:date('n');
if($month==1){
$prev = 12;
$prevyear = $year - 1;
}else{
$prev = $month-1;
$prevyear = $year;
}
//实现下一月和下一年
if($month==12){
$next = 1;
$nextyear = $year + 1;
}else{
$next = $month + 1;
$nextyear = $year;
}
if($month<=9){
$month='0'.$month;
}
$days=date('t',strtotime(date($year.'-'.$month)));
$w=date('w',strtotime(date($year.'-'.$month.'-1')));
$firstday=1-$w;
前端主要代码:
<style>
td,th{
/*width:100px!important;
height: 100px!important;*/
/*background:#ccc;*/
/*border:1px solid #ccc;*/
text-align: center;
border: 1px solid #ccc!important;
position: relative;
}
th{
padding-bottom: 30px!important;
}
tr{
height: 83px;
}
.order1{
position: absolute;
left:15px;
}
.order2{
position: absolute;
right:15px;
}
</style>
<div class="panel panel-default panel-intro">
<div class="panel-heading">
</div>
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<!-- <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> -->
</div>
<div class="row">
<div class="col-md-4">
<h4>{$year}-{$month} <a href="{:url('index',['y'=>$prevyear,'m'=>$prev])}">上一月</a><a href="{:url('index',['y'=>$nextyear,'m'=>$next])}">下一月</a></h4>
</div>
<div class="col-md-7 text-right">
<h4>平台至今总收入:{$revenue} , 本月营收:{$monthTot} </h4>
</div>
<div class="col-md-1">
<a class="btn btn-primary" href="{:url('export',['time'=>$year.'-'.$month])}">导出</a>
</div>
</div>
<h2></h2>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th>星期六</th>
</tr>
</thead>
<tbody>
{php}
for($i=$firstday;$i<=$days;){
echo "<tr>";
for($j=1;$j<=7;$j++){
if($i<=0 || $i>$days){
echo "<td></td>";
}else{
if($new[$i]['amount']){
echo "<td>
<span>$i</span>
<br>
<br>
<span class='order1'>
<a class='btn btn-success btn-xs btn-dialog' href='financial/financial/order?time=$year-$month-$i' title='当日订单列表'>".$new[$i]['amount']."</a>
</span>
<span class='order2'>
<a class='btn btn-info btn-xs btn-dialog' href='financial/financial/order?time=$year-$month-$i' title='当日订单列表'>".$new[$i]['tot']."笔</a>
</span>
</td>";
}else{
echo "<td>
<span>$i</span>
</td>";
}
}
$i++;
}
echo "</tr>";
}
{/php}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
效果图: