<?php

echo "<table class=\"table table-hover table-bordered\">";
echo "<thead>";
echo "<tr>";
$result=mysqli_query($con,"SELECT day FROM time_slot ORDER BY day;");

while($row=mysqli_fetch_array($result))
{
    $days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
    $day = $row['day']-1;
    $day = $days[$day];
    echo '<th>';
    echo $day;
    echo '</th>';
}
echo "</tr>";
echo "</thead>";

require('../includes/connection.php');

$result=mysqli_query($con,"SELECT * FROM time_slot ORDER BY day DESC;");

while($row=mysqli_fetch_array($result))
{
    echo "<tbody>";  
    echo "<tr>";

This portion of data should be display vertically in table with respect to Day

这部分数据应该相对于Day在表格中垂直显示

    //This code to split time into intervals

    $starttime = $row['start_time'];  // your start time
    $endtime = $row['end_time'];  // End time
    $duration = $row['slot_time'];  

    $array_of_time = array ();
    $start_time    = strtotime ($starttime); //change to strtotime
    $end_time      = strtotime ($endtime); //change to strtotime

    $add_mins  = $duration * 60;

    while ($start_time <= $end_time) // loop between time
    {
        echo '<td>';
        echo "<div align=\"center\">";
        print_r(date ("h:i", $start_time) ."-". date("h:i", $start_time += $add_mins));
        //
        echo "</br><input type=\"radio\" name=\"texi\" value=\"1\" ></input>";
        echo '</td>' ;
        echo '</div>';
    }
    echo "</tr>";
    echo "</tbody>";
}            

mysqli_close($con);

echo  "</table>
       </div>
       <input type=\"submit\" value=\"Book Slot\"  class=\"button_drop\">
       </form>";
?>

I want to show time slots vertically with respect to day in table. This is the output of this code:

我想在表格中垂直显示时间段。这是此代码的输出:

But I want to display time which is showing horizontally that should be shown vertically. Eg. 1-3, 3-5, 5-7 of first row should be shown below Monday, then next row should be shown below Tuesday and so on.

但是我希望显示水平显示的时间,应该垂直显示。例如。第一行的1-3,3-5,5-7应该在星期一下面显示,然后下一行应该在星期二下面显示,依此类推。

1 个解决方案

#1


1

Try using a query like this:

尝试使用这样的查询:

SELECT day FROM time_slot ORDER BY time_slot, day;

That should get the data in an easier order to process. I can't see your exact data structure but it looks like you should get 7x 01:00-03:00, then 7x 03:00-05:00 etc. Each set should be in order by day. Then you can just write out your <td>s in the order the data comes from the DB. Keep track of when the day value changes (or just count up to 7) and start a new <tr> at that time.

这应该使数据更容易处理。我看不到你确切的数据结构,但看起来你应该得到7x 01:00-03:00,然后是7x 03:00-05:00等。每一组都应该按天排序。然后你可以按照数据来自数据库的顺序写出你的。跟踪日期值的变化(或者只计数到7)并在那时开始新的。

更多相关文章

  1. 最近用php写了一个从mysql数据库随机读取n条记录
  2. 根据cookie数据连接两个表
  3. mysql数据库监控利器lepus天兔工具安装和部署
  4. 数据库连接“Mysql”丢失,缺少mysql.sock
  5. 如何从php中的数据库表创建表单下拉列表?
  6. Open edX数据结构Mysql edxapp
  7. powerdesigner连接MySQL数据库时出现Non SQL Error : Could not
  8. 通用的增删改查方法(反射)附带MySQL数据库连接
  9. VS2015 使用Mysql-connector/c++ 链接数据库(环境配置)

随机推荐

  1. Android Studio Gradle相关异常记录
  2. 笔记——Android 中的小细节
  3. AndroidManifest.xml文件详解(service)
  4. 【Android】Wifi管理与应用
  5. java.lang.ClassCastException: android.
  6. Android处理各种触摸事件
  7. Android周报第二十四期
  8. android 支持 安装到 SD卡
  9. Android创建和删除桌面快捷方式
  10. android 小问题记录