使用mysql查询在php中制作动态数组

时间:2015-11-20 08:53:40

标签: php mysql dynamic-tables

你好我在这里遇到一个小问题: 我有HTML代码:

<div class="prog-container">
<h4>programa imeras</h4>
<ul class="nav navbar-nav" id="program">
<li role="presentation" class><a data-toggle="pill"href="#day1">D</a></li>
<li role="presentation" class><a data-toggle="pill"href="#day2">T</a></li>
        <li role="presentation" class><a data-toggle="pill" href="#day3">T</a></li>
        <li role="presentation" class><a data-toggle="pill" href="#day4">P</a></li>
        <li role="presentation" class><a data-toggle="pill" href="#day5">P</a></li>
        <li role="presentation" class><a data-toggle="pill" href="#day6">S</a></li>
        <li role="presentation" class><a data-toggle="pill" href="#day0">K</a></li>




    <div class="tab-content">
        <div id="day1" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
        <div id="day2" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
        <div id="day3" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
        <div id="day4" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
        <div id="day5" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
        <div id="day6" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
        <div id="day0" class="tab-pane">
            <?php echo get_table(); ?>
        </div>
    </div>
    </div> 

这里是php代码:

function get_table(){
        $hour = 14;
        $minute = 45;
        //making connection
        $dayOfWeek = date('w');
        $conn = mysql_connect('localhost','root','');
        if(!$conn){
            die('can not connect to server!');
        }
        $db = mysql_select_db('testing',$conn);
        if(!$db){
            die('can not connect to database!');
        }
        //query select 
        $sql = mysql_query("select title,TIME_FORMAT(timeStart,'%H:%i') as timeStart,TIME_FORMAT(timeEnd,'%H:%i') as timeEnd from shows where day = $dayOfWeek ");
        $rowResult = mysql_num_rows($sql);


        echo '<table id=progContainer >';

        for($x = 0; $x < $rowResult; $x++){
            //start time 
            $timeStart = mysql_result($sql,$x,'timeStart');
            $time_start = strtotime($timeStart);
            $startH = date('H',$time_start);
            $startM = date('i',$time_start);
            //end time 
            $timeEnd = mysql_result($sql,$x,'timeEnd');
            $time_end = strtotime($timeEnd);
            $endH = date('H',$time_end);
            $endM = date('i',$time_end);
            //next time
            if($x != $rowResult-1){
                $timeNext = mysql_result($sql,$x+1 ,'timeStart');
                $time_next = strtotime($timeNext);
                $nextH = date('H',$time_next);
                $nextM = date('i',$time_next);


            }
            if($x != $rowResult-1){
                if($startH > $endH)
                    $endH += 24;
                if($hour < $endH)
                    $endM += 60;
                if($endH > $nextH)
                    $nextH += 24;
                if($hour < $nextH)
                    $nextM += 60;
                if($startH <=  $hour &&  $hour <= $endH && $startM <=  $minute &&  $minute < $endM){
                    echo '<tr class="current">';

                }else if($endH <=  $hour &&  $hour <= $nextH && $endM <=  $minute &&  $minute < $nextM ){
                    $next = true;
                    echo '<tr class="current">';
                }
            }else if($x == $rowResult-1 ){
                if($startH > $endH)
                    $endH_int += 24;
                if( $hour < $endH)
                $endM_int += 60;
                if($startH <=  $hour &&  $hour <= $endH && $startM <=  $minute &&  $minute < $endM){
                    echo '<tr class="current">';
                }
            }


            //rendering
                echo '<td>'.$startH.':'.$startM.'-'.$endH.':'.$endM.'</td>';
                echo '<td>&nbsp;&nbsp;</td><td>'.mysql_result($sql, $x, 'title').'</td> ';
                echo'</tr>';    
        }


        echo '</table>';
        mysql_close($conn);
    }

所以我尝试制作动态表格,显示星期几并更改现在正在播放的节目的背景,当我在列表中选择其他日子时更改当天,并将用mysql帮助显示其他日子!当我选择其他日子时,我的日子不会改变:/ thnx很多寻求帮助和尝试:)

0 个答案:

没有答案