我有一张看起来像这样的表
vendorschedule(定期更新后会更新)
id vendorid datee day timee text
1 1 08/03/2015 Mon 6-7 A
2 1 08/04/2015 Tue 7-8 B
3 1 08/05/2015 Wed 8-9 C
4 1 08/06/2015 Thur 9-10 D
5 1 08/07/2015 Fri 10-11 E
6 1 08/08/2015 Sat 11-12 F
7 1 08/09/2015 Sun 12-13 G
8 1 08/05/2015 Wed 11-12 C1
5 1 08/07/2015 Fri 6-7 E1
我希望以当前一周的表格形式替换数据
Time Mon Tue Wed Thur Fri Sat Sun
6-7 A E1
7-8 B
8-9 C
9-10 D
10-11 E
11-12 F
12-13 C1 G
在这个显示时间和日期,即星期一等等,是固定的,只有值会改变。此视图将用于显示每个供应商的当前周数据
从here我开始知道如何从当前日期获取7天的数据。但在我的场景中,如何在开始日是星期一时获取数据。
目前我拥有的代码是(现在它是静态的)
<table class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
</thead>
<tbody>
<tr>
<td>Before 0700</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>7:00-8:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>8:00-9:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>9:00-10:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>10:00-11:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>11:00-12:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>12:00-13:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>13:00-14:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>14:00-15:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>15:00-16:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>16:00-17:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>17:00-18:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>18:00-19:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>19:00-20:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>20:00-21:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>After 21:00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
答案 0 :(得分:0)
试试这段代码。虽然我不会说它是一种非常干净的方式,但它肯定会奏效。代码的第一部分将有助于查找当前周的开始和结束日期,您可以根据您的要求使用日期
<?php
/*****start the code to find the starting and ending date of current week*****/
$monday = strtotime("last monday");
$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;
$sunday = strtotime(date("Y-m-d",$monday)." +6 days"); //+6 can be changed to +1,+2...so on acc to your need
$this_week_sd = date("m/d/Y",$monday);
$this_week_ed = date("m/d/Y",$sunday);
echo "Current week range from $this_week_sd to $this_week_ed ";
/***end of above code***/
$sql4 = "SELECT * FROM vendorschedule where datee='".$this_week_sd."' and vendorid='".$vendorid."' and timee='7-8'";
$result4 = mysqli_query($con, $sql4) or die(mysqli_error($sql4));
if (mysqli_num_rows($result4) > 0)
{
while($row4 = mysqli_fetch_assoc($result4))
{
$text1=$row4['text'];
}
}
?>