Currently I'm creating a simple calendar with javascript and php using mysqli so I'm trying to pass all my records from database to a variable in javascript so that I can use it to display in my calendar to show a date as event when I click the date which is the 25th it will display the data.
this is my database I want to display
My php code
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "calendar";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM bootstrap" ;
$result = mysqli_query($conn,$sql);
$myArray = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$myArray[] = $row['title'];
}
}
else {
print_r ($myArray);
}
?>
Here is the part of my javascript I want to pass the result from my query
Javascript code
//here I want to pass the array result from my query in php
var codropsEvents = {
'08-25-2021' : '<span>New Year\'s day</span>',
'11-23-2021' : '<span>Second Event</span>,
'12-2-2021' : '<span>Last Event</span>
};