利用时间通过php从数据库中检索特定内容 [英] Using the time to retrieve specific content from a database through php

查看:45
本文介绍了利用时间通过php从数据库中检索特定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Am trying to display information on a website based on the local time. Each element has 3 elements.

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 中是否有任何脚本可以做到这一点?

What I want to do is load a specific element from the database, based on the day and time. How do I go about it? Is there any scripts to do this in php/mysql?

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

I've managed to get all the elements from the database to load based on the day, using the script below;

<? 

$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>
<? } ?>

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

This currently will display all the elements in the database for today with their start and end times i.e.

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

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

What I now need to do is figure out a way to select the right item and display it based on the current time. How do I do this???

推荐答案

好吧,在我绞尽脑汁阅读了一些文章之后,我找到了一个让它工作的方法,而且非常简单.查看下面的查询以了解更多详情.

OK after cracking my brains and going through some articles, I figured out a way to make it work and it's quite simple. Check the query below for more details.

<? 

$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>
<? } ?>

这篇关于利用时间通过php从数据库中检索特定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆