「name」(イベントの)列と「day」(完全に、「Monday」、「Tuesday」など)の列を持つデータベーステーブルがあります。イベントのwhile
後に括弧で囲まれたその日が続くループでは、非常に簡単です。
その日が次の日に当たる日付を体系的に毎日置き換える方法はありますか?したがって、月曜日は6月11日、火曜日は6月12日などになります。
私はこれらの線に沿って何かを試しましたが、変数は「name」の各行で同じままです-遡及的にこれは理にかなっています。
$today = date("l");
$todays_date = date("j M");
if ($row['day'] == $today) {
$date = $todays_date;
}
else if (day == date("l", strotime("+1 day")) {
$date = date("j M", strotime("+1 day"));
}
echo "<option>" . $row['name'] . " (" . $date . ")</option>";
編集
これが私が今持っているものです:
function getClubs() {
connect();
date_default_timezone_set('Europe/London');
$day = date("l");
$time = date("G");
if ($time >= 21) {
$day = date('l', strtotime($day .' +1 day'));
}
if ($day == Monday) {
$query = "SELECT * FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY')";
}
else if ($day == Tuesday) {
$query = "SELECT name FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY')";
}
else if ($day == Wednesday) {
$query = "SELECT name FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY')";
}
else if ($day == Thursday) {
$query = "SELECT name FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY')";
}
else if ($day == Friday) {
$query = "SELECT name FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'FRIDAY', 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY')";
}
else if ($day == Saturday) {
$query = "SELECT name FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY')";
}
else if ($day == Sunday) {
$query = "SELECT name FROM nights WHERE city = 'Cambridge' ORDER BY FIELD(day, 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY')";
}
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
// $items[] = array($row['name']);
$day = $row['day'];
function getDateString($day){
if (date("l")==$day){
return date("j M");
}
else {
$date = strtotime("next $day");
return date("j M",$date);
}
}
echo "<option>" . $row['name'] . " (" . getDateString($row['day']) . ")</option>";
}
}
}