PHP does not work when fetching data from a database

0
<?php
require_once('bdd.php');


$sql = "SELECT * FROM events ";

$req = $bdd->prepare($sql);
$req->execute();

$events = $req->fetchAll();

?>

After making the connection with my database I use this code to return the values in a modal window to edit them.

The problem is that it only brings 1 of the many values in the modal.

and you can see it here. link when double click on an event is pressed.

my input and data return input is this

<div class="form-group">
                    <label for="color" class="col-sm-2 control-label">Importancia</label>
                    <div class="col-sm-10">
                      <select name="color" class="form-control importancia" id="color" disabled>
                          <option value="">SELECCIONAR</option>
                          <option style="color:#000;" value="#000">&#9724; SIN TRASCENDENCIA</option>
                          <option style="color:#008000;" value="#008000">&#9724; IMPORTANTE</option>
                          <option style="color:#FF0000;" value="#FF0000">&#9724; ULTIMA HORA</option>
                          <option style="color:#40E0D0;" value="#40E0D0">&#9724; EFEMERIDES</option>
                           <option style="color:#FFD700;" value="#FFD700">&#9724; OTROS</option>


                        </select>  
                    </div>
                  </div>

What I do not understand is that I do not have the data placed in the editing window.

here the rest of the code

var date = new Date();
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString().length == 1 ? "0"+(date.getMonth()+1).toString() : (date.getMonth()+1).toString();
var dd  = (date.getDate()).toString().length == 1 ? "0"+(date.getDate()).toString() : (date.getDate()).toString();

$('#calendar').fullCalendar({
    header: {
         language: 'es',
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay',

    },
    defaultDate: yyyy+"-"+mm+"-"+dd,
    editable: true,
    eventLimit: true, // allow "more" link when too many events
    selectable: true,
    selectHelper: true,
    select: function(start, end) {

        $('#ModalAdd #start').val(moment(start).format('YYYY-MM-DD HH:mm:ss'));
        $('#ModalAdd #end').val(moment(end).format('YYYY-MM-DD HH:mm:ss'));
        $('#ModalAdd').modal('show');
    },
    eventRender: function(event, element) {
        element.bind('dblclick', function() {
            $('#ModalEdit #id').val(event.id);
            $('#ModalEdit #title').val(event.title);
            $('#ModalEdit #color').val(event.color);
            $('#ModalEdit').modal('show');
        });
    },
    eventDrop: function(event, delta, revertFunc) { // si changement de position

        edit(event);

    },
    eventResize: function(event,dayDelta,minuteDelta,revertFunc) { // si changement de longueur

        edit(event);

    },
    events: [
    <?php foreach($events as $event): 

        $start = explode(" ", $event['start']);
        $end = explode(" ", $event['end']);
        if($start[1] == '00:00:00'){
            $start = $start[0];
        }else{
            $start = $event['start'];
        }
        if($end[1] == '00:00:00'){
            $end = $end[0];
        }else{
            $end = $event['end'];
        }
    ?>
        {
            id: '<?php echo $event['id']; ?>',
            title: '<?php echo $event['title']; ?>',
            start: '<?php echo $start; ?>',
            end: '<?php echo $end; ?>',
            color: '<?php echo $event['color']; ?>',
            lugar: '<?php echo $event['lugar']; ?>',
        },
    <?php endforeach; ?>
    ]
});

function edit(event){
    start = event.start.format('YYYY-MM-DD HH:mm:ss');
    if(event.end){
        end = event.end.format('YYYY-MM-DD HH:mm:ss');
    }else{
        end = start;
    }

    id =  event.id;

    Event = [];
    Event[0] = id;
    Event[1] = start;
    Event[2] = end;

    $.ajax({
     url: 'editEventDate.php',
     type: "POST",
     data: {Event:Event},
     success: function(rep) {
            if(rep == 'OK'){
                alert('Evento se ha guardado correctamente');
            }else{
                alert('No se pudo guardar. Inténtalo de nuevo.'); 
            }
        }
    });
}

});
    
asked by Juan Ortiz 01.07.2018 в 20:17
source

0 answers