I was given an assinment to finish a project from an advanced Web Aplication student and im trying to understand all the code, but it is becoming very difficult. I'd appreciate some help with the code lines. Im already commenting the lines to help me advance. Can you comment the lines as well so I can advance in the code? Thanks for all the cooperation in advance. Its merely a challenge so no pressure for anyone, i just ask for good will kind of help. Code is in portuguese, hope it doesnt make much difference, if so, i'll clarify it.

(Code verified)

```
<?php

require_once("top.php"); //incluir ficheiro uma única vez

$idvoo= !empty($_GET["idvoo"]) ? $_GET["idvoo"] : null; //verifica se a variável existe ou retorna valor nulo

$query= "select a.ID, a.TotalFilas, a.LugaresPorFila_Esquerda,".
" a.LugaresPorfila_Central, a.LugaresPorFila_Direita FROM aviao as a".
" WHERE a.ID = (SELECT v.IDAviao FROM voo as v WHERE v.ID = ?)" ; //Consulta os parâmetros especificados no código da 
                                                              //respectiva tabela (aviao)
 //echo $query;
 //die;

$stmt = $mydb->prepare($query); //Prepara a consulta para a base de dados
//var_dump($mydb->error);

$stmt->bind_param("i", $idvoo); //Muda o valor do parãmetro "?" para "idvoo"

$stmt->execute();               //Executa o mysql

$result = $stmt->get_result();  //Obtem os resultados
$aviao = $result->fetch_assoc();//Cria um array associativo do resultado mysql

//var_dump($aviao);

```

Thank you all for your answers, they were extremely fast and I could understand a lot more of the code besause of them. Specially the statement query which i had never used before. If you still have the time I have more lines of code I need to understand, no need to comment on repeated statements such as "$stmt" "query" etc.

```
echo "<h1>Lugares</h1>";
echo "<table border=1>";
echo "<thead><tr><th>Fila</th>"; //Construção da Tabela Lugares

$letras = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I');//Criação de um array com as letras relativas a cada linha de lugares

$posicao = 0;
for ($i=0; $i < $aviao['LugaresPorFila_Esquerda']; $i++) { 
    echo "<th>".$letras[$posicao]."</th>";
    $posicao++;
}
for ($i=0; $i < $aviao['LugaresPorfila_Central']; $i++) { 
    echo "<th>".$letras[$posicao]."</th>";
    $posicao++;
}
for ($i=0; $i < $aviao['LugaresPorFila_Direita']; $i++) { 
    echo "<th>".$letras[$posicao]."</th>";
    $posicao++;
}

echo "</tr>";

//Consulta os parâmetros especificados no código da tabela bilhete
$query= "select b.ID, b.IDVoo, b.NumFila, b.LetraLugar,".
" b.Estado, v.ID as IDVoo FROM bilhete as b 
INNER JOIN voo as v ".
" ON b.IDVoo = v.ID".                                               
" WHERE ((b.IDVoo=?) OR (? is NULL)) AND (b.Estado='L') ORDER BY b.NumFila, b.LetraLugar" ;

$stmt = $mydb->prepare($query);

$stmt->bind_param("ii", $idvoo,$idvoo);

$stmt->execute();

$result = $stmt->get_result();

echo "<table border=1>";
        echo "<tr>";
        echo "<th>Bilhete Nº:</th>";
        echo "<th>Fila:</th>";
        echo "<th>Lugar:</th>";
        echo "</tr>";
while ($bilhete = $result->fetch_assoc()){

    //if ($bilhete["Estado"] == "L") {

        echo "<tr>";
        echo '<td class="form-control"><a class="btn btn-success btn-sm"     href="carrinho.php?id='.$bilhete["ID"].'">  Adicionar </a></td>';
        echo "<td>" .$bilhete["NumFila"]."</td>";
        echo "<td>" .$bilhete["LetraLugar"]."</td>";
        echo "</tr>";
//  }

}
echo "</table>";

```