이것은 정말로 나를 미치게하므로, 제발 도와주세요.PHP를 사용하여 현재 날짜를 선택하십시오.
아래 코드와 같이이 코드는 다음 7 일간의 날짜 목록을 표시합니다.
내가 원하는 코드를 얻으십시오.
- 디스플레이 "오늘과"내일 "대신 해당 날짜입니다. 날짜가 추가 선택하면
- "현재 "클래스를, 그것은 다른 색으로 강조 표시됩니다 이런 식으로.
- "오늘 "해야 페이지가 처음로드 될 때 기본적으로 선택.
아래 코드는이 요구 사항을 달성
<?php
$today = date("d-m-Y", strtotime('today'));
$tomorrow = date("d-m-Y", strtotime('tomorrow'));
echo '
<li><a href="?date='.$today.'">'.(($_GET['date'] == $today) ? '<span class="current"' . '>Today</span>' : 'Today').'</a></li>';
echo '
<li><a href="?date='.$tomorrow.'">'.(($_GET['date'] == $tomorrow) ? '<span class="current"' . '>Tomorrow</span>' : 'Tomorrow').'</a></li>';
for ($time = strtotime('+2 days'), $i=0; $i < 5; $time = strtotime('+1 days', $time), $i++) {$date = date("d-m-Y", $time);
echo '
<li><a href="?date='.$date.'">'.(($_GET['date'] == $date) ? '<span class="current">' : '') . date("D jS", $time) . ((isset($_GET['date']) && $_GET['date'] == $date) ? '</span>' : '') . "</a></li>";}
?>
그러나 최근에 나는 d-m-Y에서 Y-m-d로 날짜의 형식을 변경해야했습니다.
이 세 번째 요구 사항의 결과로 "Today"에 대한 것이 기본적으로 더 이상 작동하지 않습니다.
<?php
$today = date("Y-m-d", strtotime('today'));
$tomorrow = date("Y-m-d", strtotime('tomorrow'));
echo '
<li><a href="?date='.$today.'">'.(($_GET['date'] == $today) ? '<span class="current"' . '>Today</span>' : 'Today').'</a></li>';
echo '
<li><a href="?date='.$tomorrow.'">'.(($_GET['date'] == $tomorrow) ? '<span class="current"' . '>Tomorrow</span>' : 'Tomorrow').'</a></li>';
for ($time = strtotime('+2 days'), $i=0; $i < 5; $time = strtotime('+1 days', $time), $i++) {$date = date("Y-m-d", $time);
echo '
<li><a href="?date='.$date.'">'.(($_GET['date'] == $date) ? '<span class="current">' : '') . date("D jS", $time) . ((isset($_GET['date']) && $_GET['date'] == $date) ? '</span>' : '') . "</a></li>";}
?>
누구에게 도움을 줄 수 있습니까?
덕분에
사전
에 나는이 지금해야하지만 그것이 페이지로드에 클래스를 추가하지 않습니다 두려워 해요. "오늘"은 기본적으로 강조 표시되지 않습니다.
나는 뭔가를 엉망으로 만들었습니까?
<?php
if(isset($_GET['date'])){
$gdate = $_GET['date'];
}
else{
$gdate = date("Y-m-d", strtotime('today')); //Or whatever arbitrary date you want.
}
$today = date("Y-m-d", strtotime('today'));
$tomorrow = date("Y-m-d", strtotime('tomorrow'));
echo '
<li><a href="?date='.$today.'">'.(($gdate == $today) ? '<span class="current"' . '>Today</span>' : 'Today').'</a></li>';
echo '
<li><a href="?date='.$tomorrow.'">'.(($gdate == $tomorrow) ? '<span class="current"' . '>Tomorrow</span>' : 'Tomorrow').'</a></li>';
for ($time = strtotime('+2 days'), $i=0; $i < 5; $time = strtotime('+1 days', $time), $i++) {$date = date("Y-m-d", $time);
echo '
<li><a href="?date='.$date.'">'.(($gdate == $date) ? '<span class="current">' : '') . date("D jS", $time) . ((isset($gdate) && $gdate == $date) ? '</span>' : '') . "</a></li>";}
?>
무엇이 당신의 질문입니까? 어디서 붙어 있니? –
'$ _GET [ 'date']'로 채워지는 것은 무엇입니까? – webbiedave
안녕 Pekka, 글쎄 날짜 형식을 chnaging 만든 문제를 해결하려면. – jamjam