開始日と終了日を持つ mysql のテーブルがあります。
1行の例は次のとおりです。
startdate -> 20121224
endate -> 20121226
title -> name
これは(OUTPUT!!!)を返します:
[{"user":"378","date":"UNIX_TIMESTAMP(startdate)","title":"name","description":"6 Days","url":"UNIX_TIMESTAMP(enddate)","bmanager":"manager name","academic_year":"20120801","division":"division name","manager_id":"3"}]
このレコードは 3 日間にわたるため、JSON で日付ごとに 1 つを出力したいと考えています (唯一の違いは日付です。以下を参照してください) 。
[{"user":"378","date":"UNIX_TIMESTAMP(1st date)","title":"name","description":"6 Days","url":"UNIX_TIMESTAMP(1st date)","bmanager":"manager name","academic_year":"20120801","division":"division name","manager_id":"3"},
{"user":"378","date":"UNIX_TIMESTAMP(2nd date)","title":"name","description":"6 Days","url":"UNIX_TIMESTAMP(2nd date)","bmanager":"manager name","academic_year":"20120801","division":"division name","manager_id":"3"},
{"user":"378","date":"UNIX_TIMESTAMP(3rd date)","title":"name","description":"6 Days","url":"UNIX_TIMESTAMP(3rd date)","bmanager":"manager name","academic_year":"20120801","division":"division name","manager_id":"3"},]
これは私が使用しているスクリプトです:
$sqldata = mysql_query('
SELECT
datediff(requests.end_date, requests.start_date) as numdays,
requests.user,
UNIX_TIMESTAMP(requests.start_date) AS date,
requests.employee AS title,
requests.days AS description,
UNIX_TIMESTAMP(requests.end_date) AS url,
business.line_manager AS bmanager,
requests.academic_year,
business.academic_year,
business.division,
line_managers.userid AS manager_id
FROM requests
INNER JOIN holiday_entitlement_business_manual AS business ON requests.user=business.userid AND requests.academic_year=business.academic_year
INNER JOIN line_managers ON business.line_manager=line_managers.name
WHERE requests.approved = 1
');
$posts = array();
while($row = mysql_fetch_assoc($sqldata))
{
$row['date'] = $row['date'].'000';
$row['url'] = $row['url'].'000';
$posts[] = $row;
}
mysql_free_result($sqldata);
die(json_encode($posts));