1
Hello, I searched how to add an array inside the other one but the result was not quite what I expected. I have the following code:
else if ($_GET['type'] == "listaJogos") {
//echo 'Tipo de operação: ' . $_GET['type'] . '<br>';
$campeonato_id = $_GET['campeonato'];
//Query que retorna a NOME_TIME, ID, DATA_HORA, TB_COTACAO_ID
$query = "SELECT GROUP_CONCAT(timee.nome_time ORDER BY timee.nome_time SEPARATOR ' X ') AS nome_time, 
        partida.id, partida.data_hora, partida.tb_cotacao_id 
        FROM tb_partida AS partida, tb_time AS timee, tb_partida_time AS partidaTime 
        WHERE (partida.id = tb_partida_id && timee.id = tb_time_id) 
        AND (partida.flag_ativo = 1 AND partida.flag_cancelado <> 1 AND partida.flag_finalizado <> 1) 
        AND partida.tb_campeonato_id = $campeonato_id 
        GROUP BY partida.id";
$query2 = "SELECT * FROM `tb_cotacao` WHERE `id` = ";
$result = mysqli_query($link, $query);
//--------------------------------------------------------------------------
while ($reg = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $registros[] = array('partida' => $reg);
    $result2 = mysqli_query($link, $query2 . $reg['tb_cotacao_id']);
    //$registros[] = array('partida' => mysqli_fetch_array($result2, MYSQLI_ASSOC));
    array_push($registros, mysqli_fetch_array($result2, MYSQLI_ASSOC));
}
$saida = json_encode(array('json' => $registros));
echo $saida;
}
Which brings me to the following exit:
"json": [
{
  "partida": {
    "nome_time": "Acreano\r X Flamengo\r",
    "id": "4",
    "data_hora": "2016-09-03 14:00:00",
    "tb_cotacao_id": "4"
  }
},
{
  "id": "4",
  "casa": "1.23",
  "empate": "2.13",
  "fora": "1.23",
  "gol_meio": "6.00",
  "mais_2gm": "7.00",
  "menos_3gm": "7.67",
  "ambas_marcam": "0.00",
  "casa_empate": "6.00",
  "fora_empate": "7.67",
  "casa_marca": "6.00",
  "fora_marca": "76.00",
  "casa_ou_fora": "76.00",
  "casavence_foramarca": "76.00",
  "foravence_casamarca": "7.00",
  "casavence_zero": "67.00",
  "foravence_zero": "67.00"
}]
I would, however, like it to have the following structure::
"json": [
{
  "partida": {
    "nome_time": "Acreano\r X Flamengo\r",
    "id": "4",
    "data_hora": "2016-09-03 14:00:00",
    "tb_cotacao_id": "4"
    "cotacoes": {
       "id": "4",
       "casa": "1.23",
       "empate": "2.13",
       "fora": "1.23",
       "gol_meio": "6.00",
       "mais_2gm": "7.00",
       "menos_3gm": "7.67",
       "ambas_marcam": "0.00",
       "casa_empate": "6.00",
       "fora_empate": "7.67",
       "casa_marca": "6.00",
       "fora_marca": "76.00",
       "casa_ou_fora": "76.00",
       "casavence_foramarca": "76.00",
       "foravence_casamarca": "7.00",
       "casavence_zero": "67.00",
       "foravence_zero": "67.00"
    }
  }
}]
If anyone can help, I’d appreciate it.
The result is as expected?
– Tiago Gomes
I managed to solve Tiago, thanks for your help and patience.
– Guilherme Ramalho
Good :). If it was with my answer mark as certain, if it was with another option enter the answer and mark as right please.
– Tiago Gomes