FULLCALENDAR (SHOW SPECIFIC EVENTS)

2

My problem is that I want to obtain specific events according to a value, and all the information of the events is retrieved from the db successfully from a file with the following code:

header('Content-Type: application/json');
$conexion = new PDO("mysql:host=localhost;dbname=scouts_601_palmira","root","");
$sql = "SELECT * FROM Eventos";
$sentencia = $conexion -> prepare($sql);
$sentencia -> execute();
$resultado = $sentencia -> fetchAll(PDO::FETCH_ASSOC);
echo json_encode($resultado);

The next file path I include in the view that the fullCalendar has ready.

events:'http://localhost/MafekingOnline/Sql/ArregloEventos.php',

What I want to achieve is that when I pass a parameter to him to compare if that event has it then he can show it, but then he omits it The code would be something like this:

header('Content-Type: application/json');
$conexion = new PDO("mysql:host=localhost;dbname=scouts_601_palmira","root","");
$sql = "SELECT * FROM Eventos WHERE Id_rama = :Id_rama";
$sentencia = $conexion -> prepare($sql);
$sentencia -> bindParam(':Id_rama', $id_rama, PDO::PARAM_STR);
$sentencia -> execute();
$resultado = $sentencia -> fetchAll(PDO::FETCH_ASSOC);
echo json_encode($resultado);

I would have to put the code of the file where I get the information from the database in the same as the fullCalendar so that I can recognize the variable (as far as it goes).

I thank you in advance for any help to find the solution.

Sources that I have consulted and that could give a clue to the solution to this problem:

Filter of events in FullCalendar

link

    
asked by Danyel Melendez Ramirez 04.10.2018 в 06:11
source

1 answer

1

And because you do not pass the id by parameter in a GET to your route:

events:'http://localhost/MafekingOnline/Sql/ArregloEventos.php?id=5',

And your ArrangeEvents.php would be:

header('Content-Type: application/json');
$conexion = new PDO("mysql:host=localhost;dbname=scouts_601_palmira","root","");
if(isset($_GET['id'])){
    $id = $_GET['id'];
}
$sql = "SELECT * FROM Eventos".(isset($id) ? " WHERE Id_rama = :Id_rama" : "");
$sentencia = $conexion -> prepare($sql);
if(isset($id)){
    $sentencia -> bindParam(':Id_rama', $id, PDO::PARAM_STR);
}
$sentencia -> execute();
$resultado = $sentencia -> fetchAll(PDO::FETCH_ASSOC);
echo json_encode($resultado);

When you need to pass to your route another id you can take it from your page, for example you can have a select with the different ids and when filling the fullcalendar you take the value of the selected option, example:

<select id="ids">
  <option value="1">Primero</option>
  <option value="2">Segundo</option>
</select>

Before initializing the fullcalendar:

var id = document.querySelector("#ids").value;

And then where is it initialized:

events:'http://localhost/MafekingOnline/Sql/ArregloEventos.php?id=${id}',

I hope it works for you:)

    
answered by 04.10.2018 / 14:55
source