-1

I have created a bootstrap calendar and I want to retrieve the event from the sql database but it is not working

I stored the start_date and end_date in the calendar with datetime data type

I followed some tutorial and write this piece of php code:

<?php
include_once ("dbconnection.php");

//load.php
$data = array();

$query = "SELECT * FROM Event ORDER BY event_id";

$statement = $connect->prepare($query);

$statement->execute();

$result = $statement->fetchAll();

foreach($result as $row)
{
 $data[] = array(
  'id'   => $row[.'event_id'.],
  'title'   => $row[.'Title'.],
  'start'   => $row[.'start_date'.],
  'end'   => $row[.'end_date'.]
 );
}

echo json_encode($data);

?>

after i run the code there is no event in the calendar

Til
  • 5,150
  • 13
  • 26
  • 34
  • 2
    You should start using some kind of IDE which would highlight syntax errors for you. VS code is a good cheap option. – Dharman Jun 16 '19 at 17:54
  • 2
    **$row[.'event_id'.]** should be **$row['event_id']**. No dots - it's not string concatenation. This is true for the other three key-value pairs in the $data array. Then **$data[] = array()** should be **$data = array()**. No need for square brackets - that's something else. (That says: the new element in the $data array is an array, so you'll have only one element in your $data array.) – muka.gergely Jun 16 '19 at 19:18
  • i've changed it and nothing has changed – Raghad Aziz Jun 16 '19 at 19:19
  • 2
    Pls, go step by step - check every line if it works, and locate the first one that doesn't. – muka.gergely Jun 16 '19 at 19:24

1 Answers1

-2

Try using

array_push($data,['id' => $row['event_id'], 'title' => $row['Title'], 'start' => $row['start_date'], 'end' => $row['end_date']]);