1
Hello.
I have a while
that prints on the screen a list of all the names of the companies in my database:
$sql = "SELECT `nomep` FROM `cadastropn` WHERE `cidade` = '$cidade'";
$result = mysqli_query($mysqli, $sql);
while($linha = $result->fetch_assoc()) {
echo '<div id="lista"><img src="_imagens/pizzaiolo_corpo-300x288.png" class="logo"><a href="javascript:mostrar();"><h2>'.$linha['nomep'].'</h2></a></div>';
Each record in this list, when clicked, makes this article shown:
<article class="detalhes">
<?php
$sql = "SELECT `nomep`, `descricao`, `funciona`,`googlemaps`, `telefone`, `cidade`, `bairro`, `endereco`, `site`, `email`, `facebook`, `googleplus` FROM `cadastropn` WHERE `cidade` = '$cidade' && `id` = '1'";
$result = mysqli_query($mysqli, $sql);
while($linha = $result->fetch_assoc()) { (...)
My question, is that this list always shows, the result of the same item, even when I click on others (which is expected because I indicated the id above) Now how to do the following: I clicked on the first item of the list and in the article details will appear the record of id = '1'
. Then I clicked on the second item of the list and in the article details will appear the record of id = '2'
, thus successively.
I advise you to use javascript and get the id of the element you clicked, and this id should be the same as the one in the database.
– Nayron Morais
@Nayronmorais Can exemplify?
– Nicolas S.