Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP开放时间及;大使馆假期_Php_Mysql_Time_Timetable - Fatal编程技术网

PHP开放时间及;大使馆假期

PHP开放时间及;大使馆假期,php,mysql,time,timetable,Php,Mysql,Time,Timetable,我一直在使用以下代码: $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(CURREN

我一直在使用以下代码:

 $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"];


                      }


}
但这只是输出地址/电子邮件等两次

有人能指出我做错了什么吗

谢谢你的帮助


编辑:我现在已经解决了这个问题,只使用了第二个查询和if/else循环。

我不会自称是专家,而且你的连接看起来非常复杂,但根据我的经验,如果你在查询中得到重复的连接,那么你没有正确分组,我在你的查询中根本看不到分组依据

希望有帮助


顺便说一下。。。您的公共假日数据来源于哪里?我正在寻找完全相同的东西,这就是我如何看到这篇文章的。

使用了第二个查询和if/else循环,它按照我的要求工作。

嗨,Dave,我们的一名工作人员正在浏览所有大使馆网站并手动收集数据。
    $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)
)
        ;";