英文:
List database data via jquery with FullCalendar
问题
以下是翻译好的部分:
我从数据库返回一些字段,包括:id、title、color、start、end、start_time、end_time和obs
在这种情况下,使用PHP文件中的while注册字段并返回JSON数组的示例如下:
$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,
'end_time' => $end_time,
'obs' => $obs
];
}
echo json_encode($events);
但是它不会在页面的HTML中返回,甚至不会列出。只返回id、start和end。
在数据库中列出记录,并通过JSON数组在fullcalendar中使用jQuery显示。
英文:
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
答案1
得分: 1
'time_end' => $time_end
应该是 'time_end' => $end_time
使用 $row_events = $resultado_events->fetch(PDO::FETCH_ASSOC)
替代 $row_events = $result_events->fetch(PDO::FETCH_ASSOC)
修正后的代码:
$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);
英文:
'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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论