2

hello i'm using fullcalendar and i want to declare event.start and event.end as a variable to use it inside my PHP code like this:

$sql = "SELECT * 
        FROM chambre
         WHERE id NOT IN (SELECT id_chambre 
                          FROM reservation_client 
                          WHERE start <= event.end 
                            AND end >= event.start)";

event.start and event.end are the two date that i select. is it possible to mix between JavaScript and php like this?

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • 1
    You need to pass the variables to PHP, by POST or GET. – Qirel Jul 20 '19 at 13:14
  • You may find https://fullcalendar.io/docs/events-json-feed to be useful reading as well, in the particular case of fullCalendar – ADyson Jul 21 '19 at 20:49

1 Answers1

3

You mix client side code (JavaScript) and server side code (PHP). With JavaScript, you can only access resources at the client (your Browser), not on the server.

I suggest making an Ajax call with parameters event.start and event.end. Then on the Sever make a php script to check the availability of the date and return the result back to the client, Example for Ajax-request:

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
  alert( "Data Saved: " + msg );
});

You have to modify the data to your requests.

The PHP-Example:

$name =  $_POST['name'];
...
// do your query to the db
// return the result:
echo json_encode($results);

Adjust the script to your needs.

ADyson
  • 57,178
  • 14
  • 51
  • 63
wado55
  • 66
  • 4