PHP:while循环元素粘在一起

时间:2016-04-30 05:53:20

标签: javascript php jquery html mysql

所以我的一些代码有一个恼人的问题。我一直在使用我在WOWAwesome的youtube频道上找到的日历代码,并使用一些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,即使我已将它们分开。

任何帮助都会很大,提前谢谢!

1 个答案:

答案 0 :(得分:0)

我认为这属于一个评论,但我不能,直到我有50个代表,所以这里。

如果您想知道为什么您的日期浮动到日历的右侧,那是因为它没有被绘制在draw_calendar()调用中。你可能会想到它在某个地方的#calendar-wrapper标签内。

至于将日历记录到jQuery标签中,您必须提供用于发表意见的代码。