发送JSON数据到空的PHP文件

时间:2019-02-07 08:55:05

标签: javascript php json

我正在为项目使用bootstrap calendar。现在,我想在一个页面上有多个日历,日历按如下方式获取事件。首先,它通过sql查询,然后对数组进行JSON编码,然后events.js读取数据以将其放入日历中。问题是因为我想在单个页面上有多个日历。我有多个JSON输出,但是我不知道如何将它们放在正确的日历中。这就是现在的样子。 preview

这是我的代码

if(isset($docenten)){
                 foreach ($docenten as $docent)
                  {

                  $DocentID = $docent["DocentID"];

                  $sqlEvents = $conn->prepare("
                  SELECT OO.OpleidingID, CO.DatumBegin, CO.DatumEind, O.Onderdeelnaam

                  FROM opleidingonderdelen OO

                  LEFT JOIN docentonderdelen DO ON OO.OnderdeelID = DO.OnderdeelID                        
                  LEFT JOIN docenten D ON DO.DocentID = D.DocentID
                  LEFT JOIN cursusonderdelen CO ON OO.OnderdeelID = CO.OnderdeelID
                  INNER JOIN onderdelen O ON OO.OnderdeelID = O.OnderdeelID

                  WHERE CO.DatumBegin AND CO.DatumEind BETWEEN :dvanaf AND :dtot
                  AND OO.OpleidingID = :OID
                  AND DO.DocentID = :DocentID
                  ");

                  $sqlEvents->bindParam(':OID', $OID, PDO::PARAM_STR);
                  $sqlEvents->bindParam(':DocentID', $DocentID, PDO::PARAM_STR);
                  $sqlEvents->bindParam(':dvanaf', $dvanaf, PDO::PARAM_STR);  
                  $sqlEvents->bindParam(':dtot', $dtot, PDO::PARAM_STR);

                  $sqlEvents->execute();


                  $calendar = array();

                  while( $rows = $sqlEvents->fetch(PDO::FETCH_ASSOC)) { 
                    $start = strtotime($rows['DatumBegin']) * 1000;
                    $end = strtotime($rows['DatumEind']) * 1000;    
                    $calendar[] = array(
                          'id' =>$rows['OpleidingID'],
                          'title' => $rows['Onderdeelnaam'],
                          'url' => "",
                      "class" => 'event-important',
                          'start' => "$start",
                          'end' => "$end"
                      );
                  }


                  $calendarData = array(
                    "success" => 1, 
                    "result"=>$calendar
                  );


                  echo json_encode($calendarData);
                   ?>
                    <table class="table table-condensed table-bordered">
                      <tr>
                        <td class="agenda-date" class="active" rowspan="4" style="height: 125px; width: 12%;">
                          <div class="dayofweek">
                            <b>
                            <?php echo $docent['Docentnaam']; ?>
                          </b>
                          </div>
                          <div class="dayofweek">
                            <?php echo $docent['Email']; ?>
                          </div>
                          <div class="shortdate">
                            <?php echo $docent['Telefoonnummer']; ?>
                          </div>
                          <div class="shortdate">
                            <?php echo $docent['Mobiel']; ?>
                          </div>
                        </td>
                      </tr>
                      <td style="width: 100%;">
                        <div class="showEventCalendar" id="">
                        </div>
                      </td>
                    </table>
                    <?php
                      }
                     }else{
                    echo "<h3>Kies een opleiding</h3>";
                  }

              ?>

          </div>

0 个答案:

没有答案