所以我的一些代码有一个恼人的问题。我一直在使用在 WOWAwesome 的 youtube channel 上找到的日历代码,并使用一些 PHP 来使用这个家伙的函数 draw_calender() 动态绘制日历:https://davidwalsh.name/php-calendar
这是我生成每个日历的代码:
<?php
$sql2 = "SELECT timeStart, timeEnd, dateFor, languageTaught, status FROM tutorslots WHERE tutorid='$tutorid'";
include('calendar/calendar.php');
$result2 = mysqli_query($conn,$sql2);
if (!$result2) {
echo 'MySQL Error: ' . mysqli_error();
exit;
}
while ($row2 = mysqli_fetch_assoc($result2)) {
$timeStart = $row2["timeStart"];
$timeEnd = $row2["timeEnd"];
$date = $row2["dateFor"];
$languageTaught = $row2["languageTaught"];
$status = $row2["status"];
$dateElements = explode('-', $date);
$year1 = $dateElements[0];
$mo = $dateElements[1];
$day1 = $dateElements[2];
$lTaught1 = $languageTaught;
echo "<h1>".$date."</h1>";
echo "<br>";
echo draw_calendar($mo,$year1,$day1,$lTaught1);
}
?>
这里是calendar.php页面
<html>
<head>
<meta name="viewport" content="width=device=width, initial-scale=1">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?php
if(!function_exists('draw_calendar')){
function draw_calendar($month,$year,$day1,$lTaught1){
switch($lTaught1){
case "eng":
$language = "English";
break;
case "oth":
$language = "Other";
break;
case "chi":
$language = "Chinese";
break;
};
/* draw table */
$calendar = '<div id="calendar-wrapper">';
/* table headings */
$calendar.= '<div id="weekday"><ul>
<li>Sunday</li>
<li>Moday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
<li>Friday</li>
<li>Saturday</li>
</ul></div><div id="calendar">';
/* days and weeks vars now ... */
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
/* row for week one */
$calendar.= '<ul class="days">';
/* print "blank" days until the first of the current week */
for($x = 0; $x < $running_day; $x++):
$calendar.= '<li class="day other-month"></li>';
$days_in_this_week++;
endfor;
/* keep going with days.... */
for($list_day = 1; $list_day <= $days_in_month; $list_day++):
/* add in the day number */
if($day1 == $list_day && $status="available"){
$calendar.= '<li class="day">';
$calendar .= '<div class="date">'.$list_day.'</div>';
$calendar .= '<div class="event">'.$language.'</div>';
} else {
$calendar.= '<li class="day">';
$calendar.= '<div class="date">'.$list_day.'</div>';
}
$calendar.= '</li>';
if($running_day == 6):
$calendar.= '</ul>';
if(($day_counter+1) != $days_in_month):
$calendar.= '<ul class="days">';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
endfor;
/* finish the rest of the days in the week */
if($days_in_this_week < 8):
for($x = 1; $x <= (8 - $days_in_this_week); $x++):
$calendar.= '<li class="day other-month"></li>';
endfor;
endif;
/* final row */
$calendar.= '</ul>';
/* end the table */
$calendar.= '</div>';
/* all done, return result */
return $calendar;
}
}
?>
</body>
</html>
抱歉,如果格式不正确。发生的事情是这样的:http://imgur.com/J6kusnR我的问题是为什么它不换一条新线路。当我尝试添加 jQuery 选项卡(生成了三个日历)时,所有选项卡都进入第一个选项卡 div,即使我已将它们分开。
任何帮助都会很大,提前致谢!
最佳答案
我认为这属于评论,但在我有 50 名代表之前我不能这样做,所以这里是。
如果您想知道为什么日期浮在日历的右侧,那是因为它不是在 draw_calendar() 调用内绘制的。您可能希望将其放在 #calendar-wrapper 标记内的某个位置。
至于将日历放入 jQuery 选项卡中,您必须提供您使用的代码,以便其他人发表意见。
关于javascript - PHP:while循环元素粘在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36951322/