-1

我正在尝试根据当地时间在网站上显示信息。每个元素有 3 个元素。

1. A start time from 01 - 24
2. An end time from 00 - 60
3. A day of the week from Mon - Sun

我想要做的是根据日期和时间从数据库中加载特定元素。我该怎么做?在 php/mysql 中是否有任何脚本可以执行此操作?

我已经设法使用下面的脚本从数据库中获取所有元素以根据日期加载;

<? 

$day = date('l');  // weekday name (lower-case L) 
$time = (int)date("Gi");

$getdays = mysql_query("SELECT * FROM pages WHERE title = '".$day."'"); $getdays = mysql_fetch_array($getdays);
$getonair = mysql_query("SELECT * FROM pages WHERE subnav LIKE '%".$getdays['id']."%' AND type = '10'"); 

while ($goa = mysql_fetch_array($getonair)) {   

?><? echo $goa['id']; ?> - <? echo $goa['content']; ?></div>
<? } ?>

这目前将显示数据库中今天的所有元素及其开始和结束时间,即

item 1
start time: 1700
end time: 1730
content: some content here

item 2
start time: 1400
end time: 1430
content: some content here

item 3
start time: 0400
end time: 1430
content: some content here

item 4
start time: 1800
end time: 1830
content: some content here

item 5
start time: 2200
end time: 2230
content: some content here

我现在需要做的是找出一种方法来选择正确的项目并根据当前时间显示它。我该怎么做呢???

4

1 回答 1

0

好吧,在绞尽脑汁并浏览了一些文章之后,我想出了一种使它起作用的方法,而且非常简单。检查下面的查询以获取更多详细信息。

<? 

$day = date('l');  // weekday name (lower-case L) 
$time = (int)date("Gi");

$getdays = mysql_query("SELECT * FROM pages WHERE title = '".$day."'"); $getdays =   
mysql_fetch_array($getdays);
$getonair = mysql_query("SELECT * FROM pages WHERE subnav LIKE '%".$getdays['id']."%'
`content` <= '".$time."' AND `caption` >= '".$time."' AND type = '10'"); 

while ($goa = mysql_fetch_array($getonair)) {   

?><? echo $goa['id']; ?> - <? echo $goa['content']; ?></div>
<? } ?>
于 2013-04-25T19:50:54.463 回答