MySQL に と を持つテーブルがありstartdate
ますenddate
。
1行の例は次のとおりです(全体の命名は無視してください):
eg
startdate -> 20121224
endate -> 20121226
title -> name
etc
私が持っている現在のスクリプトはうまく機能し、行ごとに JSON に追加されますが、.... したい.... mysql 行ごとに開始日と終了日を取得し、開始日と終了日を含む各日付を JSON に追加しますエンコード。
したがって、上記の 1 行の例ではなく、次のように返されます。
[{
"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"
}]
各日付の 1 つの行に対して 3 つの JSON が返されます。
[{
"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"
}, ]
JSON
<?php
header('Content-type: text/json');
$lmanager = $_GET["lmanager"];
$sqldata = mysql_query('
SELECT
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 AND line_managers.userid = '.$lmanager.'
');
$posts = array();
while($row = mysql_fetch_assoc($sqldata))
{
$row['date'] = $row['date'].'000';
$row['url'] = $row['url'].'000';
$row['description'] = $row['description'].' Days';
$posts[] = $row;
}
mysql_free_result($sqldata);
die(json_encode($posts));
?>