首先非常感谢各位前辈高手这几天的帮助,我从中学到了很多,因为我接触php时间不长,很多函数都不熟练,做起东西来比较吃力.....我现在想实现一个周视图,对应日期和时间 08/22(星期一) 08/23(星期二) 08/24(星期三) 08/25(星期四) 08/26(星期五) 08/27(星期六) 08/28(
00:00
01:00
02:00
03:00
04:00
05:00
06:00
07:00 显示从数据库查出的数据
08:00
09:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
21:00
22:00
23:00 下面是我整合的代码,请各位帮着看看啊,怎么改能实现这个效果。。
$year=2011;
$week=34; $weekstart=strtotime(date('Y-m-d',strtotime("{$year}W{$week}1")));//一周起始日期
$weekstartday=date("d",$weekstart);
$aWeek = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$re="<table width=auto cellspacing=\"1\" cellpadding=\"5\" class=\"tablebord\">";
$re.="<tr><td width=\"10%\"></td>";
$arRows=array();
$datearr=array();
for ($i=0;$i< 7;$i++){
$thetime=strtotime("+$i day",$weekstart);
$weekstr = $aWeek[date('w',$thetime)];
$month = date('m',$thetime);
$day=date('d',$thetime);
$date=date("Y",$thetime)."-".$month."-".$day;
$datearr[]=date("Y",$thetime)."-".$month."-".$day;
$result=$db->query("select workplan.id as id,workplan.title as title,workplan.startdate as startdate,workplan.actorid from workplan inner join users on users.id=workplan.actorid where actorid=1 and startdate like '".$date."%'");
while ($rows=$result->fetch_assoc())
{
$arRows[date('G', strtotime($rows['startdate']))][] = $rows;
}
$re.="<td width=\"10%\" align=\"center\" style=\"font-size:12px\"><strong>{$month}/{$day}({$weekstr})</strong></td>";
}
$re.="</tr>";
for($j=0; $j<24; $j++)
{
$trBg = '';
if($j%2 == 0){
$trBg = 'F8F8F8';
}//css if end $re .= sprintf("<tr><td width=\"150px\" align=\"center\" style=\"background-color:#".$trBg."\"><strong>"."%02d:00 </strong></td><td style=\"background-color:#".$trBg."\" align=\"left\">",$j); if($arRows[$j]) {
$ch = '';
foreach($arRows[$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re .= "</td>";
for ($p=1;$p<7;$p++){ $re .= sprintf("<td style=\"background-color:#".$trBg."\" align=\"left\">",$j);
if($arRows[$j]) {
$ch = '';
foreach($arRows[$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re.="</td>";
}//$p for end
$re.="</tr>";
}//$j for end
$re.="</table>";
00:00
01:00
02:00
03:00
04:00
05:00
06:00
07:00 显示从数据库查出的数据
08:00
09:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
21:00
22:00
23:00 下面是我整合的代码,请各位帮着看看啊,怎么改能实现这个效果。。
$year=2011;
$week=34; $weekstart=strtotime(date('Y-m-d',strtotime("{$year}W{$week}1")));//一周起始日期
$weekstartday=date("d",$weekstart);
$aWeek = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$re="<table width=auto cellspacing=\"1\" cellpadding=\"5\" class=\"tablebord\">";
$re.="<tr><td width=\"10%\"></td>";
$arRows=array();
$datearr=array();
for ($i=0;$i< 7;$i++){
$thetime=strtotime("+$i day",$weekstart);
$weekstr = $aWeek[date('w',$thetime)];
$month = date('m',$thetime);
$day=date('d',$thetime);
$date=date("Y",$thetime)."-".$month."-".$day;
$datearr[]=date("Y",$thetime)."-".$month."-".$day;
$result=$db->query("select workplan.id as id,workplan.title as title,workplan.startdate as startdate,workplan.actorid from workplan inner join users on users.id=workplan.actorid where actorid=1 and startdate like '".$date."%'");
while ($rows=$result->fetch_assoc())
{
$arRows[date('G', strtotime($rows['startdate']))][] = $rows;
}
$re.="<td width=\"10%\" align=\"center\" style=\"font-size:12px\"><strong>{$month}/{$day}({$weekstr})</strong></td>";
}
$re.="</tr>";
for($j=0; $j<24; $j++)
{
$trBg = '';
if($j%2 == 0){
$trBg = 'F8F8F8';
}//css if end $re .= sprintf("<tr><td width=\"150px\" align=\"center\" style=\"background-color:#".$trBg."\"><strong>"."%02d:00 </strong></td><td style=\"background-color:#".$trBg."\" align=\"left\">",$j); if($arRows[$j]) {
$ch = '';
foreach($arRows[$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re .= "</td>";
for ($p=1;$p<7;$p++){ $re .= sprintf("<td style=\"background-color:#".$trBg."\" align=\"left\">",$j);
if($arRows[$j]) {
$ch = '';
foreach($arRows[$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re.="</td>";
}//$p for end
$re.="</tr>";
}//$j for end
$re.="</table>";
id title startdate
1 测试1 2011-08-25 11:30:00
2 测试2 2011-08-26 15:00:00
下面是我整理的那个php代码 $year=2011;//得到的年份
$week=34;//得到的周 $weekstart=strtotime(date('Y-m-d',strtotime("{$year}W{$week}1")));//一周起始日期
$weekstartday=date("d",$weekstart);
$aWeek = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$re="<table width=auto cellspacing=\"1\" cellpadding=\"5\" class=\"tablebord\">";
$re.="<tr><td width=\"10%\"></td>";
$arRows=array();
$datearr=array();
for ($i=0;$i< 7;$i++){
$thetime=strtotime("+$i day",$weekstart);
$weekstr = $aWeek[date('w',$thetime)];
$month = date('m',$thetime);
$day=date('d',$thetime);
$date=date("Y",$thetime)."-".$month."-".$day;
$datearr[]=date("Y",$thetime)."-".$month."-".$day;
$result=$db->query("select id,title,startdate from workplan like '".$date."%'");
while ($rows=$result->fetch_assoc())
{
$arRows[date('G', strtotime($rows['startdate']))][] = $rows;
}
$re.="<td width=\"10%\" align=\"center\" style=\"font-size:12px\"><strong>{$month}/{$day}({$weekstr})</strong></td>";
}
$re.="</tr>";
for($j=0; $j<24; $j++)
{
$trBg = '';
if($j%2 == 0){
$trBg = 'F8F8F8';
}//css if end $re .= sprintf("<tr><td width=\"150px\" align=\"center\" style=\"background-color:#".$trBg."\"><strong>"."%02d:00 </strong></td><td style=\"background-color:#".$trBg."\" align=\"left\">",$j); if($arRows[$j]) {
$ch = '';
foreach($arRows[$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re .= "</td>";
for ($p=1;$p<7;$p++){ $re .= sprintf("<td style=\"background-color:#".$trBg."\" align=\"left\">",$j);
if($arRows[$j]) {
$ch = '';
foreach($arRows[$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re.="</td>";
}//$p for end
$re.="</tr>";
}//$j for end
$re.="</table>";
$week=34;//得到的周 $weekstart=strtotime(date('Y-m-d',strtotime("{$year}W{$week}1")));//一周起始日期
$weekstartday=date("d",$weekstart);
$aWeek = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$re="<table width=auto cellspacing=\"1\" cellpadding=\"5\" class=\"tablebord\">";
$re.="<tr><td width=\"10%\"></td>";
$arRows=array();
$datearr=array();
for ($i=0;$i< 7;$i++){
$thetime=strtotime("+$i day",$weekstart);
$weekstr = $aWeek[date('w',$thetime)];
$month = date('m',$thetime);
$day=date('d',$thetime);
$date=date("Y",$thetime)."-".$month."-".$day;
$datearr[]=date("Y",$thetime)."-".$month."-".$day;
$result=mysql_query("select id,title,startdate from workplan where startdate like '".$date."%'");
while ($rows=mysql_fetch_assoc($result))
{
$w = date('w', strtotime($rows['startdate']));
$arRows[$w][date('G', strtotime($rows['startdate']))][] = $rows;
}
$re.="<td width=\"10%\" align=\"center\" style=\"font-size:12px\"><strong>{$month}/{$day}({$weekstr})</strong></td>";
}
$re.="</tr>"; for($j=0; $j<24; $j++)
{
$trBg = '';
if($j%2 == 0){
$trBg = 'F8F8F8';
}//css if end $re .= sprintf("<tr><td width=\"150px\" align=\"center\" style=\"background-color:#".$trBg."\"><strong>"."%02d:00 </strong></td><td style=\"background-color:#".$trBg."\" align=\"left\">",$j);
for ($p=1;$p<7;$p++){ $re .= sprintf("<td style=\"background-color:#".$trBg."\" align=\"left\">",$j);
if($arRows[$p][$j]) {
$ch = '';
foreach($arRows[$p][$j] as $v) {
$re .= "$ch<a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong\" ><font style=\"color:blue\" title=\"日程安排\">$v[title]</font></a>";
$ch = ' | ';
}//foreach end
}
$re.="</td>";
}//$p for end
$re.="</tr>";
}//$j for end
$re.="</table>";
前辈啊,我又遇到了个问题,就是我加了个div,想要给这个div加上事件,可是获取不到div的id啊,
$year=2011;//得到的年份
$week=34;//得到的周
$weekstart=strtotime(date('Y-m-d',strtotime("{$year}W{$week}1")));//一周起始日期
$weekstartday=date("d",$weekstart);
$aWeek = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$re="<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" class=\"tablebord\">";
$re.="<tr><td width=\"10%\"></td>";
$arRows=array();
$datearr=array();
for ($i=0;$i< 7;$i++)
{ $thetime=strtotime("+$i day",$weekstart);
$weekstr = $aWeek[date('w',$thetime)];
$month = date('m',$thetime);
$day=date('d',$thetime);
$date=date("Y",$thetime)."-".$month."-".$day;
$result=mysql_query("select id,title,startdate from workplan where startdate like '".$date."%'");
while ($rows=mysql_fetch_assoc($result))
{
$w = date('w', strtotime($rows['startdate']));
$arRows[$w][date('G', strtotime($rows['startdate']))][] = $rows;
}//while end
$re.="<td width=\"12%\" align=\"center\" style=\"font-size:12px\"><strong>{$month}/{$day}({$weekstr})</strong></td>";
}//for end $re.="</tr>";
for($j=0; $j<24; $j++)
{
$trBg = '';
if($j%2 == 0){
$trBg = 'F8F8F8';
}//css if end
$re .= sprintf("<tr><td class=\"weektd\" align=\"center\" style=\"background-color:#".$trBg."\"><strong id=\"".$j."time\">"."%02d:00 </strong></td>",$j);
for ($p=1;$p<=7;$p++)
{ $re .= sprintf("<td class=\"weektd\" style=\"background-color:#".$trBg."\" align=\"left\"><div class=\"lcyworkplan\" title=\"查看日程安排\" \" ondblclick=\"lcy_tiaozhuan('".$uid."','".$datearr."','','add')\" id=\"".$j."lcyworkplan\" name=\"lcyworkplan\">",$j);
if($arRows[$p][$j])
{ foreach($arRows[$p][$j] as $v)
{ list($startdate1,$startdate2)=explode(" ",$v['startdate']);
$re .= "<span width=\"100%\"><li>".$startdate2."</li><font style=\"color:blue\" title=\"日程安排\"><a href=\"index.php?action=showputongXiangxi&id=$v[id]&type=putong&workplantype=$v[workplantype]\">$v[title]</a></font></span>"; }//foreach end
}
$re.="</div></td>";
}//$p for end $re.="</tr>";
}//$j for end
$re.="</table>";
您再给我看看吧,麻烦您了...http://topic.csdn.net/u/20110829/23/1ce85dc9-6174-4475-ad29-546db38d8c5f.html