Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8543633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:21:07+00:00 2026-06-11T12:21:07+00:00

I am building a website where users can reserve appointments. I am currently building

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:21:08+00:00Added an answer on June 11, 2026 at 12:21 pm

    A possible solution is to use associative arrays in php :

    $assoc = array("key" => "value");
    

    When you fetch your database records you can do something like this :

    $array = array();
    while($row = $stmt->fetchObject()){
    $array[$row -> date] = $row;
    }
    
    echo json_encode($array);
    

    For sorting, you can use the ksort ( http://php.net/manual/en/function.ksort.php ) php function, to sort the array by key.

    Now you will have a Javascript Object and not Javascript array.
    Now you can iterate the object with for .. in javascript loop ( How to Loop through plain JavaScript object with objects as members? )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Users on a website I'm building can request the availability of user names on
I am building a website templating system where multiple user can create their own
I'm building an app that allows users to view pictures off a website. I
I'm building a website. It has groups that users can join. The difference between
The website that I'm building includes a section where two users can interact. I
I'm building a website with Rails which can let user check if some domains
I am building a website that has a system where users can send messages
I'm building a Rails 3 app where users can select one of a number
So I'm building a website where basically users can write stories and each story
I'm building a website where I will have users logging into the site from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.