I am building a website where users can reserve appointments.
I am currently building a javascript app for the project, where user can pick a date from a calendar and see the available appointments. When I am building the calendar, I need to color dates by available appointments (ex. green if there's any).
In order to do that I need to iterate a javascript array that contains all available reservations. At the moment it looks something like this:
[Object, Object, Object...]
Where the object is a javascript object that contains appointment info. Here is the php service that serves the JSON:
<?php
require_once('../include/dbconnect.php');
$sql = "SELECT appointment.example,...
person.example,...
FROM appointment, person
WHERE appointment.reserved=0";
$stmt = $db->prepare($sql);
$stmt->execute();
$array = array();
while($row = $stmt->fetchObject()){
array_push($array, $row);
}
echo json_encode($array);
?>
So this finally brings us to the question.
For easier javascript array scanning, I'd need an array/object includes appointments arranged/sorted by date. Then when I am creating an element that represents the date, I can check the object for matching data. Data like this:
{
15.09.2012 : Object,
16.09.2012 : Object{
appointment1 : Object,
appointment2 : Object
}
}
In the database an appointment has an attribute "date" which is currently a string like "16.09.2012". Should I also change it to unix timestamp?
How should I change the PHP service to output a JSON object that includes appointments filed under dates?