gpt4 book ai didi

javascript - 如何在javascript中使用PHP调用SQL记录

转载 作者:行者123 更新时间:2023-11-29 21:21:04 25 4
gpt4 key购买 nike

<?php include('db.php'); 

//it's connect the database to server

$sql = "select * from event";
$query = mysql_query ($sql);
?>


<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
defaultDate: '2016-03-01',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
<?php while($rs = mysql_fetch_array ($query)){
?>
{
title: '<?php echo $rs['title']?>',
start: '<?php echo $rs['date']?>'
},
<?php }?>
]
});
});

只要我的数据库表中有记录,我就想显示标题和日期。但这段代码不起作用。谢谢

最佳答案

试试这个

<?php include('db.php'); 

//it's connect the database to server

$sql = "select * from event";
$query = mysql_query ($sql);
$events = array();
while($rs = mysql_fetch_array ($query)){
$events[] = array(
'title' => $rs['title'],
'start' => date('Y-m-d H:i:s', strtotime($rs['date']))
);
}
?>


<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
defaultDate: '2016-03-01',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: <?php echo json_encode($events)?>
});
});

关于javascript - 如何在javascript中使用PHP调用SQL记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com