I have the following code that generates a JSON file, it works fine, but I must change it to send the data between the controller and the model.
include "conex.php";
$sql= "select * from timetables";
$query = $con->query($sql);
// Fetch tha data from the database
$timetables = array();
while ($row = mysqli_fetch_array($query)) {
$timetable = new stdClass();
$timetable->name = $row{'name'};
$timetable->image = $row{'image'};
$timetable->date = date('j', strtotime($row{'date'})); // date : type DATE. For example: 2016-09-07
$timetable->month = date('n', strtotime($row{'date'}));
$timetable->year = date('Y', strtotime($row{'date'}));
$timetable->start_time = $row{'start_time'} ? date('H:i', strtotime($row{'start_time'})) : ''; // start_time : Must be 24 hour format. For example: 18:00
$timetable->end_time = $row{'end_time'} ? date('H:i', strtotime($row{'end_time'})) : ''; // end_time : Must be 24 hour format. For example: 20:30
$timetable->color = $row{'color'};
$timetable->description = utf8_encode(nl2br($row{'description'}));
array_push($timetables, $timetable);
}
echo json_encode($timetables);
I did the following but with that I can not divide the date field as it happens in the previous code.
class IdController{
public function idController(){
$id_URL = $_GET["id"];
$respuesta = IdModels::idModel($id_URL, "timetables");
echo json_encode($respuesta);
}
}
I need in the controller to be able to divide the date like this:
$timetable->date = date('j', strtotime($row{'date'}));
$timetable->month = date('n', strtotime($row{'date'}));
$timetable->year = date('Y', strtotime($row{'date'}));
How could I do it?
This is the Model:
class IdModels{
public function idModel($id, $tabla){
$stmt = Connex::conect()->prepare("SELECT name, image, date, start_time, end_time, color, description FROM $tabla WHERE court = $id");
$stmt -> execute();
return $stmt -> fetchAll();
$stmt -> close();
}
}