In my page, I have a list of shops with some information. For each shop, I have a button that opens a modal where I want to show all the information about the shop.
I put my modal inside the while that generates the list and the first result is correctly shown into the modal, but if I click the second, third etc... shop in the list, I see the information about the first shop (now I tried only with the name of the shop). I don't understand why.
Is it possible for each store to show its information? Is it mandatory to use ajax?
I check this question How can i show data into bootstrap panel dynamically by javascript? but it didn't helped me.
This is the code with the php that generates my list, the button that opens the modal, and the modal:
<?php
echo'<section class="col-xs-12 col-sm-6 col-md-12">';
$sql = "SELECT nome_L, tipocucina_TC, wifi_L, tipolocale_TL, descrizione_L, indirizzo_L, fasciaprezzo_L, convenzione_L, image_thumb_L FROM locale l
JOIN tipocucina c On l.TipoCucina_L = c.IDtipocucina_TC
JOIN tipolocale t On l.TipoLocale_L = t.IDTipolocale_TL
WHERE TRUE";
$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
while($row = mysqli_fetch_array($result))
{
$nome_Local = $row['nome_L'];
$descrizione_Local = $row['descrizione_L'];
$indirizzo_Local = $row['indirizzo_L'];
$tipocucina_Local = $row['tipocucina_TC'];
$tipolocale_Local = $row['tipolocale_TL'];
$immagine_Local = $row['image_thumb_L'];
//START MODAL
echo'
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">'.$nome_Local.'</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
';
//END MODAL
echo'<article class="search-result row">
<div class="col-xs-12 col-sm-12 col-md-3">
<a href="#" title="Lorem ipsum" class="thumbnail"><img src="images/locals/'.$immagine_Local.'"/></a>
</div>
<div class="col-xs-12 col-sm-12 col-md-2" style="width: 18%;">
<ul class="meta-search">
<li><i class="fa fa-cutlery fa-lg"></i> <span>'.$tipocucina_Local.'</span></li>
<li><i class="fa fa-coffee fa-lg"></i> <span>'.$tipolocale_Local.'</span></li>
</ul>
</div>
<div class="col-xs-12 col-sm-12 col-md-7 excerpet" style="width: 55%;">';
echo"<h3><a>".$nome_Local."</a></h3>";
echo'<i class="fa fa-compass"> </i>'.$indirizzo_Local.'</i>';
echo"<br>";
echo'<p class="local-description">'.$descrizione_Local.'</p>';
//BUTTON THAT OPEN MY MODAL
echo'<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> Show more </button>';
echo'
</div>
<span class="clearfix borda"></span>
</article>';
}
$conn->close();
?>
Hopefully, I have described the problem correctly.
id=myModal. This is why bootstrap will always open the same. Give them unique ids and adjust the opening button accordingly to the same ids (in data-target)