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条)

报告相同问题?