我一直在使用這種代碼:PHP的開放時間和節假日使館
$rawsql = "SELECT
*
FROM
_erc_foffices n
INNER JOIN
_erc_openings o ON n.id = o.branch_id AND o.dotw = DAYOFWEEK(CURRENT_DATE())
INNER JOIN
_erc_openings_times t ON o.id = t.opening_id
WHERE
(
UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) BETWEEN UNIX_TIMESTAMP(CONCAT(CURRENT_DATE(), ' ', t.open)) AND UNIX_TIMESTAMP(CONCAT(CURRENT_DATE(), ' ', t.close))
)
AND
(
n.id = %d
)
;";
$sql = sprintf($rawsql, mysql_real_escape_string($id));
$result = mysql_query($sql);
/*These if & while statements decide whether or not the information should be displayed. If no results are returned from the query above then an alternative message is shown.*/
if(mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<div class='address'><p>" . $row["title"] . "<br/>";
echo $row["address_1"] . "<br/> " . $row["address_2"] . "<br/> " . $row["address_3"] . "<br/> " . $row["address_4"] . "<br/> " . $row["address_5"] . "</p>";
echo "<div class='buttons'><img src='http://localhost/erc/images/texttouser_button.png'/><br/><a href='" . $row["url"] . "' target='blank'><img src='http://localhost/erc/images/website_button.png'/></a></div></div>";
echo "<div class='email'>" . $row["email"] . "</div>";
$extra_notes = $row["extra"];
}
} else {
$embassy_closed = mysql_query("SELECT * FROM _erc_foffices WHERE id = '$embassy_id'");
while($row = mysql_fetch_array($embassy_closed))
{
echo "<div class='address'><p>" . $row["title"] . "<br/>";
echo $row["address_1"] . "<br/> " . $row["address_2"] . "<br/> " . $row["address_3"] . "<br/> " . $row["address_4"] . "<br/> " . $row["address_5"] . " <font color='red'>The embassy is closed.</font></p>";
echo "<div class='buttons'><img src='http://localhost/erc/images/texttouser_button.png'/><br/><a href='" . $row["url"] . "' target='blank'><img src='http://localhost/erc/images/website_button.png'/></a></div></div>";
echo "<div class='email'>" . $row["email"] . "</div>";
$extra_notes = $row["extra"];
}
}
這需要開放時間從數據庫中使館並決定使館是否是當前打開的。如果不是,則顯示「使館關閉」的消息。現在我需要在公衆假期增加了,所以我改變了查詢,看起來像這樣:
$rawsql = "SELECT
*
FROM
_erc_foffices n
INNER JOIN
_erc_openings o ON n.id = o.branch_id AND o.dotw = DAYOFWEEK(CURRENT_DATE())
INNER JOIN
_erc_openings_times t ON o.id = t.opening_id
LEFT JOIN
_erc_holidays h ON h.branch_id = n.id
WHERE
(
UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) BETWEEN UNIX_TIMESTAMP(CONCAT(CURRENT_DATE(), ' ', t.open)) AND UNIX_TIMESTAMP(CONCAT(CURRENT_DATE(), ' ', t.close))
)
AND
(
n.id = %d
)
AND
(
UNIX_TIMESTAMP(CURRENT_TIMESTAMP())
NOT BETWEEN UNIX_TIMESTAMP(h.begins_at) AND UNIX_TIMESTAMP(h.ends_at)
)
;";
但這只是輸出地址/電子郵件等的兩倍。
有人能指出我做錯了嗎?
感謝所有幫助
編輯:我現在已經解決了這個問題,只是採用了一個2查詢的if/else循環。
嗨Dave,我們的工作人員正在瀏覽所有大使館網站並手動收集數據。 – 2011-04-18 08:10:45