我试图根据当地时间在网站上显示信息。每个元素都有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
我现在需要做的是找出一种方法来选择正确的项目并根据当前时间显示它。我该怎么做???
答案 0 :(得分: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>
<? } ?>