dongyange1101 2014-10-17 11:57
浏览 29
已采纳

PHP - JSON没有输出

I have written a code that outputs all termins i have the day. The calendar for this is already finished. But the program output, I want to use with python don't work.

My code:

<?php

mysql_connect(deleted);
mysql_select_db("DB1367141")

$day = date("d");
$month = date("m");
$year = date("Y");

$result = mysql_query("SELECT * FROM entries WHERE day = '$day' AND month = '$month' AND year = '$year' ORDER BY hour DESC, minute");

$array = {};

while($obj = mysql_fetch_object($result))
{
    if($obj->hour != "--")
        $hour = splitf("%02d", $obj->hour);
    else
        $hour = $obj->hour;

    if($obj->minute != "--")
        $minute = splitf("%02d", $obj->minute)
    else
        $minute = $obj->minute;

    array_push($array, {"hour":$hour, "minute":$minute, "text":$obj->tex});
}

var_dump($array);
echo json_encode($array);

?>

But if i run it, it neither outputs the array than an "echo('hi');"

I tried out to put this echo at the begin, at the end and in the middle. But the output is the same: nothing

In another forum I found out that I have to write:

$array = array();

But the output is the same: nothing.


i tryed both, right syntax and error report. as i changed $array = array(); nothing changed. i added two lines in my .htaccess to get better error report, and it outputed a 500 Internal Server Error.

  • 写回答

2条回答 默认 最新

  • doudao2407 2014-10-17 14:52
    关注

    Might I recommend you try converting your date storage to timestamps in the name of simplicity. That way you only need to check that the entry is between the first and last second of "today".

    You'd save yourself quite a lot of hassle and if you really need to output as in that JSON layout could just parse the timestamp using:

    while($obj = mysql_fetch_object($result)) {
        $array[] = array(
            'hour' => date('H', $obj->timestamp,
            'minute' => date('i', $obj->timestamp,
            'text' => $obj->tex
        );
    }
    echo json_encode($array);
    
    date('n', strtotime($strTimestamp));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装