0
Hello! I’m facing a problem with a dynamic modal. On an Index page, the user will select a state and a city and will be forwarded to the modals page; On this page will be presented the Branches of the chosen city (code not yet created) and all Brazilian states in a navbar, states that one or more cities have a subsidiary (these states have status = 0
) will call a modal with these cities (these cities possess status = 0
) , the other states (which have no city with branch/ status = 1
) will be forwarded to an error page.
Looking in the bank for information according to the state and city chosen on the previous page
<?php
$query3 = "select * from estados where estado_id = ".$_GET['estados']."";
$dt3 = mysqli_query($conn, $query3);
$row3 = mysqli_fetch_array($dt3);
?>
Creating a navbar with all states
<nav id="nav2" class="navbar navbar-default">
<button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target="#estados">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse" id="estados">
<ul class="nav navbar-nav">
<?php
$query4 = "select * from estados";
$dt4 = mysqli_query($conn, $query4);
while ($row4 = mysqli_fetch_array($dt4)){
$nome2 = $row4['nome'];
$estado_id2 = $row4['estado_id'];
$active = "";
$caret = "class=\"caret\"";
if ($estado_id2 == $row3['estado_id']){
$active = "class=\"active\"";
};
if($row4['status']>0){
echo "<li $active><a href='erro.php'>$nome2</a></li>";
}else{
echo "<li $active ><a href='' data-toggle='modal' data-target='#modal".$estado_id2."'>$nome2<span $caret></span></a></li>";
};
?>
</ul>
</div>
</nav>
Modal
<div class="modal fade" role="dialog" tabindex="-1" id="modal<?php echo $estado_id2 ?>">"
<div class="modal-dialog">
<div class="modal-content desktop-hide">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×
</button>
</div>
<div class="modal-body">
<p class="panel-info">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<?php
$query6 = "SELECT * FROM cidades WHERE estado_id = ".$estado_id2." AND status = 0";
$dt6 = mysqli_query($conn, $query6);
while($row6 = mysqli_fetch_array($dt6)){
$nome3 = $row6['nome'];
echo "<li><a href=''>$nome3</a></li>";
}
?>
</ul>
</nav>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Fechar
</button>
</div>
</div>
<div class="modal-content mobile-hide">
<div class="modal-body">
<p class="panel-info">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<?php
$query6mob = "SELECT * FROM cidades WHERE estado_id = ".$estado_id2." AND status = 0";
$dt6mob = mysqli_query($conn, $query5);
while($row6mob = mysqli_fetch_array($dt6mob)){
$nome3mob = $row6mob['nome'];
echo "<li><a href=''>$nome3mob</a></li>";
}
?>
</ul>
</nav>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Fechar
</button>
</div>
</div>
</div>
</div>
<?php };?>
The Problem: For some reason, which is what I want to find out, the links of the States are disfigured, were to be like the State of Acre as shown in the image!
How these links appear in HTML source code?
– Sam
Also note that we missed closing the
while ($row4 = mysqli_fetch_array($dt4)){
.– Sam
@Sam, now I’ve closed the
while ($row4 = mysqli_fetch_array($dt4)){
after closing the last modal, but still it is the same!– user150548
@Sam Regarding the source code, I edited the question again, check out the second image!
– user150548
the
data-target='#modal".$estado_id2."'
was not properly calling the modal, due to variableestado_id2
was being closed before the</ul> </div> </nav>
, to fix this, I closed thewhile ($row4 = mysqli_fetch_array($dt4))
after the modals.– user150548