1
$query_number = 2;
$query = "SELECT * FROM $table ORDER by date desc limit $query_number";
$results = mysql_query($query);
$message['posts'] = $results;
echo json_encode($message);
exit;
我得到對象的數組有多個鍵:
Array
(
[0] => stdClass Object
(
[ID] => 4983
[post_id] => 56357
[date] => 2016-06-04 23:45:28
)
[1] => stdClass Object
(
[ID] => 4982
[post_id] => 56241
[date] => 2016-06-04 22:58:27
)
)
我通過AJAX整個陣列發送到JS。
但是,我想將日期格式更改爲「ago」並將其發送給js。
我有「前」功能,但我不知道如何定位date
值並將其放回原來的位置(替換)。
任何幫助將不勝感激!
謝謝!
@steveKim你在使用'mysql_fetch_object'嗎?在我的例子中,它將與'mysql_fetch_array'一起工作 –