有时内容会加载,有时则不会

时间:2010-10-20 23:50:50

标签: php debugging

我有以下脚本和网站http://cacrochester.com,有时右侧边栏的内容会加载,有时则不会。我想如果它是你在页面上的前几次,它会说没有安排任何事件。

我完全不知道为什么会这样。数据库中的数据没有变化。

如果您需要我发布更多代码,请告诉我。

感谢您的帮助!

<?php

            $dummy = 0;
            $headingLength = 0;
            $descriptionLength = 0;
            $shortHeading = 0;
            $shortDescription = 0;
            $todayYear = date('Y');
            $todayMonth = date('m');
            $todayDay = date('d');
            $events = new dates();
            $noEvents = 0;

            //get the number of upcoming events
            $numEvents = $events->getNumberEvents();

            //get the actual events
            $results = $events->getRows();

            //used if there are not at least 5 events to fill up the event scroller
            switch($numEvents) {
                case 1: $dummy = 4; break;
                case 2: $dummy = 3; break;
                case 3: $dummy = 2; break;
                case 4: $dummy = 1; break;
            }

            //loops through all of the events in the table and adds them to the list
            foreach($results as $result) 
            {   
                $strippedHeading = stripslashes($result['heading']);
                $strippedDescription = stripslashes($result['description']);
                $headingLength = strlen($strippedHeading);
                $descriptionLength = strlen($strippedDescription);
                $shortHeading = $strippedHeading;
                $shortDescription = $strippedDescription;
                $time = strftime("%l:%M %P", $result['time']);
                $location = $result['location'];
                $startDate = getdate($result['start_date']);
                $today = getdate();

                //if the events are NOT in the past...          
                if($startDate >= $today)
                {       
                    //if we are at the end of the array, add the class 'last' to the li
                    if(current($result) == end($result)) 
                    {
                        echo "<li class=\"last\"><a href=\"Calendar.php\"><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></a></li>".PHP_EOL;
                    } 
                    else 
                    {
                        echo "<li><a href=\"Calendar.php\"><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></a></li>".PHP_EOL;
                    }                   
                    $noEvents = 1; 
                }   

                //if there is not at least 5 events, it repeats the events in the list until there are 5 total
                elseif($dummy > 0 && $numEvents > 0) 
                {                   
                    //if the events are NOT in the past...
                    if($startDate >= $today) 
                    {   
                        //if we are at the end of the array, add the class 'last' to the li
                        if($dummy == 0) 
                        {
                            echo "<li class=\"last\"><a href=\"Calendar.php\"><h4>".$shortHeading."</h4> ".$shortDescription."</a></li>".PHP_EOL;  
                            $dummy--;
                        } 
                        else 
                        {
                            echo "<li><a href=\"Calendar.php\"><h4>".$shortHeading."</h4> ".$shortDescription."</a></li>".PHP_EOL;  
                            $dummy--;
                        }

                        //if we have 5 events, do not add anymore
                        if($dummy < 0) 
                        {
                            break;
                        }
                    }

                    $noEvents = 1;
                }  
            }

            //if there are no events, display the no events message
            if($noEvents == 0)
            {
                echo "<li class=\"last\"><a href=\"Calendar.php\"><h4>No Events Scheduled</h4></a></li>".PHP_EOL;  
            }
            ?>

1 个答案:

答案 0 :(得分:1)

当你执行$startDate >= $today时,你试图比较两个数组,这不是一个好主意。只需使用简单的时间戳,它应该可以正常工作:

$startDate = $result['start_date'];
$today = strtotime('today');

此外,我不确定这是否是拼写错误:current($result) == end($result),但不应该是$results,这是数组名称吗?