Php 动态colspan内表,内while循环
我正在用php制作一个周历,使用一个多维表。 第一列应该是医生的名字,在右边的一周中,这些事件可能需要2、3甚至5天的时间。颜色设置如下:Php 动态colspan内表,内while循环,php,while-loop,html-table,Php,While Loop,Html Table,我正在用php制作一个周历,使用一个多维表。 第一列应该是医生的名字,在右边的一周中,这些事件可能需要2、3甚至5天的时间。颜色设置如下: Green - 1day event Red - 2day event Blue - 3day event....etc 从突出显示的蓝色单元格中可以看到,我的colspan有问题。因为它是动态创建的,所以我必须找到一种方法,根据前几天(如果有1天或更长时间的事件)正确地“推送”列 简而言之,通过mysql/php,我正在做的就是: while ($do
Green - 1day event
Red - 2day event
Blue - 3day event....etc
从突出显示的蓝色单元格中可以看到,我的colspan有问题。因为它是动态创建的,所以我必须找到一种方法,根据前几天(如果有1天或更长时间的事件)正确地“推送”列
简而言之,通过mysql/php,我正在做的就是:
while ($doctors = mysqli_fetch_assoc($result)) {
$output .="<tr>";
$output .="<td rowspan=2>".$doctors["name"]."</a></td>";
//A for loop to create the days on the top
for ($n=0; $n<=6; $n++)
{
//doesnt matter how they are made
}
//an extra td for a button (dont care about this now)
$output .="<td></td>";
$output .="</tr><tr>";
//now here are the events
for ($n=0; $n<=6; $n++)
{
$searchday = $dayArray[$n]["year"]."-".$dayArray[$n]["month"]."-".$dayArray[$n]["day"];
//here is the Query that brings the event for the $searchday, which is the day of the column cell
//After i retrieve the results with a fetch_assoc, i assigned the value of day to $info_tab bellow.
//Lets say it returns an array $info holding the event, and the type of event (how many days)
$info_tab = $info["event_details"];
$background_color = $info["event_days"];
$ids = array(1,2,3,4,5); //The background color cases...1day event, 2day event, etc
if(in_array($background_color, $ids)){
switch ($background_color) {
case 1:
$output .= '<td colspan="1" class="wk-cspan-1">'.$info_tab.'</td>';
break;
case 2:
$output .= '<td colspan="2" class="wk-cspan-2">'.$info_tab.'</td>';
break;
case 3:
$output .= '<td colspan="3" class="wk-cspan-3">'.$info_tab.'</td>';
break;
case 4:
$output .= '<td colspan="4" class="wk-cspan-4">'.$info_tab.'</td>';
break;
case 5:
$output .= '<td colspan="5" class="wk-cspan-5">'.$info_tab.'</td>';
break;
default:
$output .= '<td colspan="1" class="wk-cspan-0">'.$searchday.'</td>';
break;
}
}else{
$output .= '<td colspan="1" class="wk-cspan-0">'.$searchday.'</td>';
}
}
$output .="</tr>";
}
while($doctors=mysqli\u fetch\u assoc($result)){
$output.=“”;
$output.=''.$doctors[“name”]。'';
//用于在顶部创建日期的for循环
对于($n=0;$nI可能会将colspan值保存在一个单独的变量中,并使用该变量将$dayArray[$n][“day”]
增加到适当的数量。虽然简单地使用hmm可能会容易得多,但有趣的是……我没有想到推送$dayArray[$n]因此,我总是尝试根据箱子里的标志来修复空的。我会试试,谢谢。不过我不得不说这是一个错误的策略。如果一个事件从一个月到下一个月重叠,你会遇到麻烦。这就是为什么我建议改为使用DateTime对象。我正在研究一个例子。谢谢s、 我能理解为什么n美元的推送会是个问题……我已经看到了你说的奇怪的结果,下个月:)顺便说一句,日历是从中取来的,但它被调整了很多…(如果有帮助的话)