0

我在活动时间表方面遇到了一些问题。我正在尝试显示当天的所有事件,但它只显示一个。我正在使用其他人编码的小cms。我只是想修复事件页面。您可以提供的任何帮助将不胜感激。

这是代码:

<?php

        for( $i = 1; $i <= 7; $i++ ) {

            $query  = $db->query( "SELECT * FROM events WHERE day = '{$i}'" );
            $num    = $db->num( $query );

            $events = array();

            $day    = strtotime( "november {$i} 2010" );
            $day    = date( "l", $day );

            while( $array = $db->assoc( $query ) ) {

                $time = strtotime( "{$time} on november {$i} 2010" );

                $events[$time] = $array['id'];

            }


    ?>

    <div class="wrapper">

        <div class="title">

            <?php

                echo $day;

            ?>

        </div>


        <?php

            if( $num != 0 ) {

        ?>

        <table width="100%" cellpadding="3" cellspacing="1">

                <tr style="background: #e9e9e9; font-weight: bold;">

                    <td width="40%">
                        Event Name
                    </td>

                    <td width="25%">
                        Host
                    </td>

                    <td width="20%">
                        Hotel
                    </td>

                    <td width="15%">
                        Time
                    </td>

                </tr>

                <?php

                    foreach( $events as $key => $value ) {

                        $query2 = $db->query( "SELECT * FROM events WHERE id = '{$value}'" );
                        $array2 = $db->assoc( $query2 );

                ?>

                <tr style="background: #f3f3f3;">

                    <td width="40%">
                        <?php
                            echo $array2['name'];
                        ?>
                    </td>

                    <td width="25%">
                        <?php
                            echo $array2['host'];
                        ?>
                    </td>

                    <td width="20%">
                        <?php
                            echo $array2['hotel'];
                        ?>
                    </td>

                    <td width="15%">
                        <?php
                            echo $array2['time'];
                        ?>
                    </td>

                </tr>

            <?php

                }

            ?>

            </table>

            <?php

                } else {

                    echo "<center>";
                    echo "There are no events for today!";
                    echo "</center>";

                }

            ?>

        </div>

    <?php
        }

    ?>
4

1 回答 1

0

您在每个循环中都覆盖了您的$day变量,因此只会显示最后一个。$events数组也是如此

于 2013-10-26T23:43:15.183 回答