将数据推送到php 5.3 vs 5.5中的数组

时间:2015-08-06 15:37:40

标签: php arrays json

我很难解决这个问题。我没有收到任何错误消息。当我在本地测试时,我的代码工作(php 5.5)。我公司使用的服务器是php 5.3.3。我的代码在服务器上不起作用。当我做var_dump时,我得到一个空数组。在本地我的数组填充了我的SQL数据库中的数据。

这是我的代码。我认为我的语法是正确的,但此时我不确定。

<?php

$sql = "SELECT * FROM $table";
$get_result = $db->query($sql);

$events = array();

foreach ($get_result as $row) {
    echo $row['event'] . '<br>';

    $date = $row['d1'];
    $ymd = date('Y-m-d', strtotime($date));

    $date2 = $row['d2'];
    $ymd2 = date('Y-m-d', strtotime($date2));

    $date3 = $row['d3'];
    $ymd3 = date('Y-m-d', strtotime($date3));

    $date4 = $row['d4'];
    $ymd4 = date('Y-m-d', strtotime($date4));

    $date5 = $row['d5'];
    $ymd5 = date('Y-m-d', strtotime($date5));
    if ($row['approved'] == 'yes') {
        if ($row['d1'] != '0000-00-00') {
            $events[] = array('id' => '' . $row['id'] . '',
                'date' => '' . $ymd . ' ' . $row['start'] . '',
                'title' => '' . $row['event'] . '',
                'description' => '' . $row['descrip'] . '',
                'startTime' => '' . $row['start'] . '',
                'endTime' => '' . $row['end'] . '',
                'url' => 'event_details.html?id=' . $row['id'] . '&data=events',
                'location' => '' . $row['addy1'] . ' ' . $row['addy2'] . ' ' . $row['addy3'] . ' ' . $row['city'] . ' ' . $row['state'] . ' ' . $row['zip'] . '',
                'eventUrl' => '' . $row['event_url'] . '',
                'subName' => '' . $row['subName'] . '',
                'subEmail' => '' . $row['subEmail'],
            );
        }
        if ($row['d2'] != '0000-00-00') {
            $events[] = array('id' => '' . $row['id'] . '',
                'date' => '' . $ymd2 . ' ' . $row['start'] . '',
                'title' => '' . $row['event'] . '',
                'description' => '' . $row['descrip'] . '',
                'startTime' => '' . $row['start'] . '',
                'endTime' => '' . $row['end'] . '',
                'url' => 'event_details.html?id=' . $row['id'] . '&data=events',
                'location' => '' . $row['addy1'] . ' ' . $row['addy2'] . ' ' . $row['addy3'] . ' ' . $row['city'] . ' ' . $row['state'] . ' ' . $row['zip'] . '',
                'eventUrl' => '' . $row['event_url'] . '',
                'subName' => '' . $row['subName'] . '',
                'subEmail' => '' . $row['subEmail'],
            );
        }
        if ($row['d3'] != '0000-00-00') {
            $events[] = array('id' => '' . $row['id'] . '',
                'date' => '' . $ymd3 . ' ' . $row['start'] . '',
                'title' => '' . $row['event'] . '',
                'description' => '' . $row['descrip'] . '',
                'startTime' => '' . $row['start'] . '',
                'endTime' => '' . $row['end'] . '',
                'url' => 'event_details.html?id=' . $row['id'] . '&data=events',
                'location' => '' . $row['addy1'] . ' ' . $row['addy2'] . ' ' . $row['addy3'] . ' ' . $row['city'] . ' ' . $row['state'] . ' ' . $row['zip'] . '',
                'eventUrl' => '' . $row['event_url'] . '',
                'subName' => '' . $row['subName'] . '',
                'subEmail' => '' . $row['subEmail'],
            );
        }
        if ($row['d4'] != '0000-00-00') {
            $events[] = array('id' => '' . $row['id'] . '',
                'date' => '' . $ymd4 . ' ' . $row['start'] . '',
                'title' => '' . $row['event'] . '',
                'description' => '' . $row['descrip'] . '',
                'startTime' => '' . $row['start'] . '',
                'endTime' => '' . $row['end'] . '',
                'url' => 'event_details.html?id=' . $row['id'] . '&data=events',
                'location' => '' . $row['addy1'] . ' ' . $row['addy2'] . ' ' . $row['addy3'] . ' ' . $row['city'] . ' ' . $row['state'] . ' ' . $row['zip'] . '',
                'eventUrl' => '' . $row['event_url'] . '',
                'subName' => '' . $row['subName'] . '',
                'subEmail' => '' . $row['subEmail'],
            );
        }
        if ($row['d5'] != '0000-00-00') {
            $events[] = array('id' => '' . $row['id'] . '',
                'date' => '' . $ymd5 . ' ' . $row['start'] . '',
                'title' => '' . $row['event'] . '',
                'description' => '' . $row['descrip'] . '',
                'startTime' => '' . $row['start'] . '',
                'endTime' => '' . $row['end'] . '',
                'url' => 'event_details.html?id=' . $row['id'] . '&data=events',
                'location' => '' . $row['addy1'] . ' ' . $row['addy2'] . ' ' . $row['addy3'] . ' ' . $row['city'] . ' ' . $row['state'] . ' ' . $row['zip'] . '',
                'eventUrl' => '' . $row['event_url'] . '',
                'subName' => '' . $row['subName'] . '',
                'subEmail' => '' . $row['subEmail'],
            );
        }
    }
}

var_dump($events);

思考?感谢您提供的任何见解!

1 个答案:

答案 0 :(得分:0)

这个问题没有语法,但它确实处理了不同版本的PHP。 JSON_PRETTY_PRINT是罪魁祸首。显然不符合5.4之前的PHP版本。删除它似乎已经解决了问题。