2013-04-25 1 views
-1

현지 시간을 기준으로 웹 사이트에 정보를 표시하려고합니다. 각 요소에는 3 개의 요소가 있습니다.PHP를 통해 데이터베이스에서 특정 콘텐츠를 검색하는 데 시간 사용

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

PHP 또는 MySQL에서이를 수행 할 수있는 스크립트가 많이 있습니다. 그냥 몇 가지 연구를해야합니다. –

+0

SQL 쿼리에서 사용할 데이터를 이스케이프 (escape)하는 방법으로'addslashes()'를 사용하지 마십시오. 대신 준비/매개 변수화 된 쿼리를 사용하십시오. – Brad

답변

0

내가 두뇌를 부수고 몇 가지 기사를 읽은 후 OK로 작동시키는 방법을 찾았으며 매우 간단합니다. 자세한 내용은 아래 쿼리를 확인하십시오.

<? 

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