Hello, I have a form where I need to load two selects which receive from the bank approximately 13,000 records each. Initially I created a function that loaded the records and printed the HTML code of the option and used it once in each select. As the performance was not satisfactory I divided the function in two so that the query was done only once but even so when it arrives in the part that must render the select there is a delay of approximately 8s for each and this in the localhost, in the server must be bigger still. I would like someone to guide me on how to optimize the loading of this page. Thank you very much in advance. Here are the codes:
I placed the form in the pastebin for better visualization and removed the form from the back to the mentioned selects: cadastra_jogo.php
Functions:
//Lista todos os times
function lista_times()
{
$link = conectar();
$query = "SELECT tb_time.id as id_time, tb_time.nome_time, tb_campeonato.nome_camp
FROM tb_campeonato, tb_time
WHERE tb_time.tb_campeonato_id = tb_campeonato.id";
$result = mysqli_query($link, $query) or die(print_r(mysqli_error()));
//return $result;
$header_atual="";
$registro = mysqli_fetch_assoc($result);
return $registro;
}
//Preenche o select com todos os times
function preenche_time_combo($registro)
{
while ($registro) {
if($registro['nome_camp'] != $header_atual){
if($header_atual != ""){
echo "</optgroup>";
}
echo "<optgroup label='".$registro['nome_camp']."'>";
$header_atual = $registro['nome_camp'];
}
echo "<option value='" . $registro['id_time'] . "'>" . $registro['nome_time'] . "</option>";
}
echo "</optgroup>";
}