在php中循环时获取下一行

时间:2016-03-10 13:11:28

标签: php

请检查我的代码和表格。我需要nex row" days"和其他条件下的starttime。

例如:如果用户在结束时间后的星期五访问网页。我需要在echo "we are here for you again saturday from 9:00

显示第二天和开始时间

表格

id  days    starttime   endtime
1   Mon     10:00   18:00
2   Tue     10:00   18:00
3   Wed     10:00   18:00
4   Thu     10:00   13:00
5   Fri     10:00   18:00
6   Sat     9:00    14:00

代码

<?php
    require_once('dbconnect.php');
    $today         = date("D M j G:i:s T Y");
    echo $today. '<br>';
    $explode       = explode(" ", $today);
    $explode_day   = $explode[0];
    $explode_time  = $explode[3];

    $select        = "SELECT id, days, starttime, endtime FROM daytime";
    $execute       = $mysqli->query($select);
    while($row = $execute->fetch_assoc()){
        $days          = $row["days"];
        $starttime     = $row["starttime"];
        $endtime       = $row["endtime"];
        if($days == $explode_day){
           if(strtotime($explode_time) < strtotime($endtime)){
               echo "we were here for you";
           }
           else{
               $j=1;
               while($j <= 6):
                   echo "we are here for you again". $days . "from". $starttime;
                   $j++;
               endwhile;
           }
        }
    }

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我使用下面的代码来获取结果。我不知道这个代码是一个好方法,但为了我的目的,它工作得很好。

WHERE