<?php
include("/var/www/2a685b61-ba1a-4056-abd9-0883231735ff/public_html/monzaclube/config.php");
$conecta = new mysqli(BD_HOST,BD_USUARIO,BD_SENHA,BD_BANCO);

$i = 1;
$sql = $conecta->query("SELECT DISTINCT E.id, E.descricao, E.data FROM eventos AS E INNER JOIN fotos AS F ON E.id = F.id_evento ORDER BY E.data DESC");
while ($consulta = $sql->fetch_assoc()){
$evNum = 'evento_'.$i;
$event[$evNum]['id'] = $consulta['id'];
$event[$evNum]['descricao'] = $consulta['descricao'];
$event[$evNum]['data'] = date("d/m/Y", strtotime($consulta['data']));
$sql1 = $conecta->query("SELECT COUNT(id) AS qFotos FROM fotos WHERE id_evento = '".$consulta['id']."'");
while ($consulta1 = $sql1->fetch_assoc()){
$event[$evNum]['qFotos'] = $consulta1['qFotos'];}
$i = $i + 1;}

$json_string = json_encode($event);

echo $json_string;
?>