Php Date 无法在服务器上运行

发布于 2024-12-13 00:16:35 字数 903 浏览 0 评论 0原文

由于某种原因,Php 日期无法在服务器上运行。

这是显示当天提示的函数。我正在使用 codeigniter 框架。在下面的函数中,我尝试打印一年中的某一天($doy)。当我转到该网址并尝试访问提示功能时,它显示一个空白页面。不打印一年中的哪一天。

public function tip(){      

    $idCount = $this->db->query('SELECT Count(*) AS COUNT FROM clickmag_tip')->result();
    $total = $idCount[0]->COUNT; 

    $time = time();
    $doy = mdate('%z', $time);
    echo $doy;
    //$day_of_year = date('z',time());

    //$doyear = date("z") + 1; 
    //echo $doyear;

    $s = mktime(date("G") + 1); 
    print date("Y/m/d h:i:s a", $s);

    if($total > 0){
        $offset = $doy % $total ;
    }

    $data = $this->db->query('SELECT * FROM table_tip LIMIT 1 OFFSET '. $offset);
    header('Content-type: text/json');
    header('Content-type: application/json');
    echo json_encode($data->result());

}

您认为问题出在哪里?我和服务员谈过,但他们也不知道。 我该如何解决这个问题?

提前致谢!

for some reason the Php date isn't working on the server.

Here is the function for displaying the tip of the day. I am using the codeigniter framework. In the function below i am trying to print the day of year ($doy). When i go to the url and try to access the tip function it shows a blank page. The day of year is not printed.

public function tip(){      

    $idCount = $this->db->query('SELECT Count(*) AS COUNT FROM clickmag_tip')->result();
    $total = $idCount[0]->COUNT; 

    $time = time();
    $doy = mdate('%z', $time);
    echo $doy;
    //$day_of_year = date('z',time());

    //$doyear = date("z") + 1; 
    //echo $doyear;

    $s = mktime(date("G") + 1); 
    print date("Y/m/d h:i:s a", $s);

    if($total > 0){
        $offset = $doy % $total ;
    }

    $data = $this->db->query('SELECT * FROM table_tip LIMIT 1 OFFSET '. $offset);
    header('Content-type: text/json');
    header('Content-type: application/json');
    echo json_encode($data->result());

}

What do you think is the problem? I talked to the server people but they also don't know.
How can i solve this?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2024-12-20 00:16:35

在输出任何内容之前,您必须输出所有标头。

您同时拥有:

echo $doy;

print date("Y/m/dh:i:s a", $s);

在此之前,

header('Content-type: text/json');
header('Content-type: application/json');

这就是导致空白页的原因。

You must output all headers before outputting anything.

You have both:

echo $doy;

AND

print date("Y/m/d h:i:s a", $s);

Before

header('Content-type: text/json');
header('Content-type: application/json');

That is what's causing the blank page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文