PHP没有生成我想要的字符串

时间:2015-08-11 17:42:16

标签: php jquery json

我有这个程序,我试图为jquery应用程序生成一个字符串,该字符串存储我的数据但无法生成正确的字符串。这是该计划:

if (!$db_selected) {
    die();
    echo "database not selected";
} else {
    $query = "SELECT * FROM `events` WHERE `event_deletion` = 1";
    $result = mysqli_query($conn, $query);
    if (!$result) {
        trigger_error("dbget: ".mysql_error()." in ".$query);
        return false;
    } else {
        while ($row = mysqli_fetch_assoc($result)) {
            $obj = array();
            array_push($obj, $row['event_ID']);
            array_push($obj, $row['event_name']);
            array_push($obj, $row['event_start']);
            array_push($obj, $row['event_end']);
            array_push($xml, $obj);
            //print_r($xml);
        }
        print(generateXML($xml));
    }
}

function generateXML($array) {
    $xmlString = "events: [";
    for ($i = 0; $i < sizeof($array); $i++) {
        $obj = $array[$i];
        //print_r($obj);
        $set = "{
            id: \'" + $obj[0] + "\'," + print($obj[0] + "");
        "title:\'" + $obj[1] + "\'," +
            "start:\'" + $obj[2] + "\'," +
            "end:\'" + $obj[3] + "\'";
        //print($set + "\r\n");
        $xmlString = $xmlString + $set;
    }
    return $xmlString = $xmlString + "]";
}

我需要最后的字符串看起来像id,name,start和end这样的格式。

events: [{
    title: 'All Day Event',
    start: '2015-02-01'
}, {
    title: 'Long Event',
    start: '2015-02-07',
    end: '2015-02-10'
}, {
    id: 999,
    title: 'Repeating Event',
    start: '2015-02-09T16:00:00'
}, {
    id: 999,
    title: 'Repeating Event',
    start: '2015-02-16T16:00:00'
},
]

我需要字符串如上所示,但是当我运行程序时我得到了这个:

  

连接made2345671044

0 个答案:

没有答案