$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 id=\"\" name=\"lr_workplan\">",$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>";
我中午发了个贴,可能大家不明白我的意思,所以我换个提法
我现在想要动态添加name为“lr_workplan”的那个div的id,应该怎么办啊,在循环里面的那个。
请大家给看看,我也没什么好办法..麻烦大家了
$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 id=\"\" name=\"lr_workplan\">",$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>";
我中午发了个贴,可能大家不明白我的意思,所以我换个提法
我现在想要动态添加name为“lr_workplan”的那个div的id,应该怎么办啊,在循环里面的那个。
请大家给看看,我也没什么好办法..麻烦大家了
"lr_workplan".$j.$p 之类的
PHP的话,可以用simplehtmldom修改id,参考 http://simplehtmldom.sourceforge.net/ 教程很简单,功能很强大。
嗯 我就是这个意思啊,一开始钻了牛角尖了
您能再帮我看看下面的代码么,我想实现一个周视图的功能 周一 周二 周三 周四 .... 周日
00:00
01:00 从数据库读出的数据 数据库数据
02:00现在的问题是,周一到周六的数据可以绑定到视图上,并且能正常显示(红色),但是到了周日就显示不了了(蓝色),这是怎么了啊,我感觉就是$p循环那错了,可是我不知道怎么改啊...麻烦大家给看看
$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 id=\"".$j."".$p."lr_workplan\" name=\"lr_workplan\">",$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/11/7a98afdd-154c-4347-8f55-71059a1b49d4.html
你需要html吗???需要的话 我给您发,
预期的表格是25行7列的结构吗?你可以先检查一下html代码中有没有周日的相关数据。
嗯 发过去了,您echo3楼的代码了啊?
1 打扫卫生 2011-08-29 14:30:00
2 加班 2011-09-04 08:20:00您看这样行吗? 还要数据库?
print_r($arRows); //打印这个数组的值发上来就可以测试了。
啊,不会吧,是这样吗???Array ( [1] => Array ( [16] => Array ( [0] => Array ( [id] => 39 [title] => 打扫卫生 [startdate] => 2011-08-29 16:00:00 [actorid] => 1 [workplantype] => P ) ) ) [0] => Array ( [8] => Array ( [0] => Array ( [id] => 40 [title] => 周末加班 [startdate] => 2011-09-04 08:00:00 [actorid] => 1 [workplantype] => P ) ) ) )
分数并不能代表水平有多高,只能说明参与的帖子比较多,接分可是个体力活啊建议楼主从结构、表现、行为代码分离开始,下功夫改变自己的编程风格。否则,代码的可读性、可维护性太差了。在两三年以前,我也没有这样的概念,后来看了《网站重构——应用Web标准进行设计》这本书以后才开始有所改变的。
对啊,我一开始也是学java的,后来该学php,没办法,公司 以前做的都是这样混在一起的....
刚刚开始学thinkphp了,哈哈,面向对象的看着舒服
这里$w的范围是0-6 , 0为周日for ($p=1;$p<=7;$p++)
这里$p是1-7循环,自然取不到周日的内容