0

I'm returning some fields from the database, namely: id, title, color, start, end, start_time, end_time and obs

In this case, when registering the fields using while in a php file and returning in a json array, the following example follows:

$query_events = "SELECT id, title, color, start, end, start_time, end_time, obs FROM events";
$resultado_events = $pdo->prepare($query_events);
$resultado_events->execute();

$events = [];

while($row_events = $result_events->fetch(PDO::FETCH_ASSOC)){
     $id = $row_events['id'];
     $title = $row_events['title'];
     $color = $row_events['color'];
     $start = $row_events['start'];
     $end = $row_events['end'];
     $start_time = $row_events['start_time'];
     $end_time = $row_events['end_time'];
     $obs = $row_events['obs'];
    
     $events[] = [
         'id' => $id,
         'title' => $title,
         'color' => $color,
         'start' => $start,
         'end' => $end,
         'start_time' => $start_time,
         'time_end' => $time_end,
         'obs' => $obs
         ];
}

echo json_encode($events);

But it is not returning in the html of the page even listing. Returns only id, start and end

list records in database and display via json array with jquery in fullcalender

3
  • did you decode your JSON data on the HTML page?
    – Tat
    Commented May 24, 2023 at 23:39
  • Hello! Yes, I used echo json_encode($events); Commented May 24, 2023 at 23:57
  • fullcalendar.io/docs/event-parsing - start_time, time_end, obs - those are all not default properties. So did you anything to configure Fullcalendar to use these for something?
    – C3roe
    Commented May 25, 2023 at 6:31

1 Answer 1

1

'time_end' => $time_end should be 'time_end' => $end_time

use $row_events = $resultado_events->fetch(PDO::FETCH_ASSOC) instead of $row_events = $result_events->fetch(PDO::FETCH_ASSOC)

CORRECTED CODE:

$query_events = "SELECT id, title, color, start, end, start_time, end_time, obs FROM events";
$resultado_events = $pdo->prepare($query_events);
$resultado_events->execute();

$events = [];

while ($row_events = $resultado_events->fetch(PDO::FETCH_ASSOC)) {
    $id = $row_events['id'];
    $title = $row_events['title'];
    $color = $row_events['color'];
    $start = $row_events['start'];
    $end = $row_events['end'];
    $start_time = $row_events['start_time'];
    $end_time = $row_events['end_time'];
    $obs = $row_events['obs'];

    $events[] = [
        'id' => $id,
        'title' => $title,
        'color' => $color,
        'start' => $start,
        'end' => $end,
        'start_time' => $start_time,
        'end_time' => $end_time,
        'obs' => $obs
    ];
}

echo json_encode($events);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.