gpt4 book ai didi

php - 显示调度算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:24:51 25 4
gpt4 key购买 nike

我正在制作一个时间表页面来展示一些节目。我想要正确的 PHP 算法根据节目开始时间显示节目。现在什么都没有显示。

这是一个链接:http://tir.fullerton.edu/schedule/schedule.php

这是我的代码:

  $result = mysqli_query($con,"SELECT * FROM schedule
ORDER BY FIELD(showDay, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'),
showStart");
echo "<br>";
$i = 8;
while($row = mysqli_fetch_array($result))
{
if ( $row['showDay'] == 'Monday')
{

if ($row['showStart'] == $i)
{
echo '<td>' . '<img class="newStyle1" src="images/'. $row['picURL'] .
'"/>'. '</br> ' . $row['showName'] . ' </td>';
}
else
{
echo "<td></td>";
}
$i++;
}

在此处安排 mysql 表:http://tir.fullerton.edu/schedule.png

最佳答案

不确定这是否是最好的方法,但这是我能想到的唯一方法......

<?php 
$con = new mysqli("localhost", "root", "password", "test");

$query = " SELECT PID, showName, showDay, showStart, showEnd, genre, picURL, showURL
FROM schedule
ORDER BY FIELD(showDay, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'), showStart";

$result = mysqli_query($con,$query);

$data = array('Monday'=>array(),
'Tuesday'=>array(),
'Wednesday'=>array(),
'Thursday'=>array(),
'Friday'=>array());

// re-order the query results so they are easier to use
// ====================================================
while($row = mysqli_fetch_assoc($result))
{
$showDay = $row['showDay'];
$showStart = $row['showStart'];
$data[$showDay][$showStart] = $row;
}

?>
<table align="center" border="1">
<tr>
<th> Show Day </th>
<th> 8:00 AM </th>
<th> 9:00 AM </th>
<th> 10:00 AM </th>
<th> 11:00 AM </th>
<th> 12:00 PM </th>
<th> 1:00 PM </th>
<th> 2:00 PM </th>
<th> 3:00 PM </th>
<th> 4:00 PM </th>
<th> 5:00 PM </th>
<th> 6:00 PM </th>
<th> 7:00 PM </th>
<th> 8:00 PM </th>
<th> 9:00 PM </th>
<th> 10:00 PM </th>
</tr>

<?php

// foreach day....
// ===============
foreach($data as $day => $times)
{
echo "<tr><td><b>$day</b></td>";

// for every displayed hour
// ========================
for ($hour=8; $hour<23; $hour++)
{
// if data exists for this time slot, show it..
// ============================================
if (isset($times[$hour]))
{
$row = $times[$hour];

echo "<td>{$row['showName']}</td>";
}
// else show an empty cell
// =======================
else echo "<td></td>";
}

echo "</tr>"; // end the row
}

echo "</table>"; // end the table

?>

产生:

enter image description here

这是我的 table :

+------+----------+---------+-----------+---------+-------+--------+---------+
| PID | showName | showDay | showStart | showEnd | genre | picURL | showURL |
+------+----------+---------+-----------+---------+-------+--------+---------+
| 1 | show 1 | Monday | 20 | 21 | NULL | NULL | NULL |
| 2 | show 2 | Monday | 13 | 21 | NULL | NULL | NULL |
| 3 | show 3 | Monday | 10 | 21 | NULL | NULL | NULL |
| 4 | show 4 | Monday | 22 | 21 | NULL | NULL | NULL |
+------+----------+---------+-----------+---------+-------+--------+---------+

并且....如果你需要证明某件事是三个小时之类的,请修改我重新排序的代码,如下所示:

while($row = mysqli_fetch_assoc($result)) 
{
$showDay = $row['showDay'];
$showStart = $row['showStart'];
$length = $row['showEnd'] - $row['showStart'];

for ($i=0; $i<$length; $i++) {
$data[$showDay][$showStart+$i] = $row;
}
}

** 今天我要走了...如果您有任何疑问,请写一些评论,我明天会检查一下。

关于php - 显示调度算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19235148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com