Show calendar generated with JS showing DB information

Asked

Viewed 92 times

0

I am generating a calendar and entering the events with information taken from the database.
When select brings only one result it is displayed normally, but when there is more than one the calendar is not displayed. The error would be in the loop repeat or not and possible to bring the results?

Select used

$sql_principal = "SELECT obras.titulo_traduzido, obras.data_lancamento, obras.id FROM obras where obras.id=1161";
$resultado_principal = mysql_query($sql_principal);

Script that generates the Calendar

    $(document).ready(function() {

        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultDate: '2015-10-23',
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: [<?php
            while($objeto = mysql_fetch_object($resultado_principal)){
                  echo "{";
                     echo "title: '{$objeto->titulo_traduzido}',";
                     echo "start: '{$objeto->data_lancamento}',";
                     echo "url: 'http://localhost/admin/filme.php?ID={$objeto->id}'";
                 echo "},";
            }
            ?>]
        });

    });

</script>
  • What’s the mistake??

  • No error returned, the screen simply goes blank, not even the calendar already generated.

  • An example, if I use "SELECT works.titulo_translated, works.data_release, works.id FROM works Where works.id=1161", it brings the calendar with the event marked on the correct day, now if select is without the WHERE enclosure to bring all events the screen is blank.

  • I took your script, put it here and it worked. You have the firefox firebug or on Chrome, press F12 and click on Console. See if there is a JS error

  • Using the Console I realized that select is bringing in a lot of records, making it take a long time to process or even lock the calendar. I put a Between in the data_release field and it worked.

  • Would you like to tell me if you have how to select the BETWEEN to get the month that is being shown by the calendar? Type, I select in the calendar the month of December and select would be: SELECT works.caption_translated, works.release, works.id FROM works data_release BETWEEN '2015-12-01' and '2015-12-31' and when I change the month in the calendar change also in select

  • You can do the following.... Store all records that came from the database in a JS array being the key of this array the "month/year" of the event, something like Wind['2015-11'][] = 'teste1' and so on. When the user changes the month in the calendar, Fullcalendar has a getMonth() function for you to get the 'active' month. Clear the calendar using the removeElements function and then add this month array corresponding to the calendar. It seems difficult but it is not.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.