The code below is a page, which the user types the name of a city, and checks for similar results. With this, it brings multiple results into a dynamically created table, depending on the data brought back from the results, this is already working Ok.
I need to make sure that when I click on the table row corresponding to the desired result, the table is "cleaned" and the row data is stored so I can work with them, displaying other data related to the city selected in the table, but when I get the element by td it always brings me the first independent result of which I click. Any ideas I can work for?
<?php include_once 'conexao.php'
?>
<html>
<head>
<title>INDEX Foruns Regionais</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scripttext="text/javascript">
function mostraConteudo() {
esconde();
var nome = document.getElementById('td').innerHTML;
alert(nome);
}
function esconde() {
$('.table td').hide();
}
$(document).ready(function(){
$("p").click(function(){
$(this).fadeOut();
});
});
</script>
</head>
<body>
<h1>Pesquisa cidade</h1>
<form onclick="" name="formulario_busca" method="post"/>
<input type="text" name="nome_cidade"/>
<input type="submit" name="busca"/>
</form>
<?php
$busca = $_POST['nome_cidade'];
$query = "SELECT * FROM cidades WHERE cidade LIKE '%".$busca."%'";
$resultado = mysqli_query($conexao, $query);
mysqli_fetch_array($resultado,$lista_Cidades);
?>
<table class="table table-striped table-bordered">
<?php
if ((mysqli_num_rows($resultado)>0) && ($busca != "") ):
while ($linha = mysqli_fetch_assoc($resultado)) {
?>
<tr>
<td id="td" onclick="mostraConteudo()"><?= $linha['cidade']?></td>
</tr>
<?php
} echo "<br/>";
endif; if(mysqli_num_rows($resultado)<=0):
echo "Cidade não encontrada";
endif;
?>
</table>
</body>
</html>