简体   繁体   English

从SQL / PHP到Java脚本获取日历事件

[英]Get calendar events from SQL/PHP to Javascript

I have an existing calendar code below: 我下面有一个现有的日历代码:

    <div class="col-md-12">
        <div id="calendar"></div>
    </div>  
    <script type="text/javascript">
        $(function(){
        $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay' }, eventLimit: true, events: [
            {
                title: 'Test Job',
                start: '2016-03-09'
            }
        ]
        }); 
        }); 
    </script>

Now what I want to do is to fetch the values of title and start from records in the database, based on specific columns. 现在,我要做的是获取title的值,并根据特定列从数据库中的记录开始。 I tried to do below, which echoes javascript from php, but it doesn't display anything. 我试图在下面做,它从php呼应javascript,但是它什么也没显示。 What it aims to do is to iterate through all the records in the database and generate the fragment in the javascript that creates an event, but it is inside php. 它旨在做的是遍历数据库中的所有记录,并在创建事件的javascript中生成片段,但它在php中。 Could you enlighten me out on possible solutions for this implementation? 您能否启发我实现该解决方案? Thanks! 谢谢!

        echo '<script type="text/javascript">';
        echo '$(function(){';
        echo "$('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay' }, eventLimit: true, events: [";
        $query = "SELECT * FROM data WHERE date >= DATE(NOW());";
        $exec = mysql_query($query,$conn);
        while ($row = $result = mysql_fetch_array($exec))
        {
            $result2--;
            echo "{title: '";
            echo $row["title"] . "',";
            echo "start: '" . $row["date"] . "'";
            echo "}";
            if ($result2<=1)
                echo ",";

        }           
        echo "]";
        echo "}); }); ";
        echo "</script>";

@Lane What you will want to do it use javascript AJAX to call the server; @Lane您将要执行的操作是使用javascript AJAX调用服务器; the server then processes the request and returns the requested data. 然后,服务器处理请求并返回请求的数据。 On successful return javascript alters the HTML to display the new data. 成功返回时,javascript会更改HTML以显示新数据。

https://api.jquery.com/jquery.get/ is a decent start playing with javascript AJAX. https://api.jquery.com/jquery.get/是使用javascript AJAX的不错的开始。 http://www.w3schools.com/php/php_mysql_connect.asp basic PHP + MySQL examples. http://www.w3schools.com/php/php_mysql_connect.asp基本的PHP + MySQL示例。

Post script: Please do not use echo in multiple lines to print out JS script. 发布脚本:请不要在多行中使用echo来打印JS脚本。 echo supports line breaks. echo支持换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM