Problem with a badly closed div

1

I have a problem, I do not know if it will be a div badly closed or poorly implemented but it is causing me enough problems because I can not find it.

In this image you can see the grid , of carousel that has a size of 10, but "evaluations" that has a size of 2 is below. I noticed on the web and the problem is a div badly closed but I can not find it.

Here's how it looks on the web:

col-md-10 should be shown closed and then col-md-2

I will leave the respective codes of index.php , carousel.php and finally navDerecho.php .

index.php

   <!DOCTYPE html>
<html lang="es">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/img/favicon.png">
    <title>Noticias</title>
    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="css/jumbotron.css" rel="stylesheet">

</head>
<?php include ('vista/overall/botones.html') ?>

<body class="pb-0">

    <div class="row">
        <?php include('vista/overall/menu.php'); ?>
        <div class="col-md-10">
            <?php  include('vista/overall/carusel.php');  ?>
        </div>
        <div class="col-md-2">
            <?php   include('vista/overall/navDerecho.php'); ?>
            <br>
        </div>

        <?php include('vista/overall/contenedor.php');?>

        <br>
        <br>

        <?php include('vista/overall/footer.html'); ?>
    </div>

    <!-- /container -->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="js/jquery-3.2.1.min.js"></script>
    <script>
        window.jQuery || document.write('<script src="../../../../assets/js/vendor/jquery.min.js"><\/script>')
    </script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="js/ie10-viewport-bug-workaround.js"></script>
    <script src="/noticiasfinal/model/ajax.js"></script>

</body>

</html>

carusel.php

    <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class=""></li>
        <li data-target="#myCarousel" data-slide-to="1" class=""></li>
        <li data-target="#myCarousel" data-slide-to="2" class="active"></li>
    </ol>
    <?php
            $link=conectar();
        $d1=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante1' "); $d2=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante2' ");
        $d3=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante3' ");
                        while($titulo=mysqli_fetch_array($d1)){   
        ?>
        <div class="carousel-inner" style="border-radius:15px;">
            <div class="carousel-item">
                <img class="first-slide" src="/noticias/img/formacion-1024x588.jpg" alt="First slide">
                <div class="container">
                    <div class="carousel-caption d-none d-md-block text-left">
                        <h1>
                            <?php echo $titulo['titulo']; ?>
                        </h1>
                        <p>
                            <?php echo $titulo['dlarga'];?>
                        </p>
                        <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                    </div>
                </div>
            </div>
            <?php }while($titulo=mysqli_fetch_array($d2)){    ?>
            <div class="carousel-item">
                <img class="second-slide" src="/noticias/img/slide-1240x327.jpg" alt="Second slide">
                <div class="container">
                    <div class="carousel-caption d-none d-md-block">
                        <h1>
                            <?php echo $titulo['titulo']; ?>
                        </h1>
                        <p>
                            <?php echo $titulo['dlarga'];?>
                        </p>
                        <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                    </div>
                </div>
            </div>
            <?php }while($titulo=mysqli_fetch_array($d3)){    ?>
            <div class="carousel-item active">
                <img class="third-slide" src="/noticias/img/prevencion-riesgos-laborales.jpg" alt="Third slide">
                <div class="container">
                    <div class="carousel-caption d-none d-md-block text-right">
                        <h1>
                            <?php echo $titulo['titulo']; ?>
                        </h1>
                        <p>
                            <?php echo $titulo['dlarga'];?>
                        </p>
                        <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                    </div>
                </div>
            </div>
            </div>
            <?php } ?>


        <a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Anterior</span>
        </a>
        <a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Siguiente</span>
        </a>
</div>

navDerecho.php

   <nav class="navbar-light bg-transparent">
    <ul class="navbar-nav ">

        <?php

                    $obtenermenu=mysqli_query($link,"Select * from tblnoticias_menu where descripcion='EVALUACIONES' ");
                    while($menu=mysqli_fetch_array($obtenermenu))
                    {
                        $submenu=mysqli_query($link,"Select * from tblnoticias_submenu where idopcion='$menu[idopcion]' and estado=1 Order By PosS");
                        if(mysqli_num_rows($submenu)>0) 
                        {
                            ?>
            <li class="nav-item dropdown mr-auto">
                <a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span><?php echo utf8_encode($menu['descripcion']); ?></span> <i class="fa fa-angle-left pull-right"></i>
                </a>

                <ul class="dropdown-menu ">
                    <?php
                            while($row1=mysqli_fetch_array($submenu))
                            {
                                ?>

                        <li>
                            <a style="text-decoration: none;color:black" href="<?php echo " /../../ ".$row1['url'];?>">
                                <?php echo utf8_encode($row1['descripcion']); ?>
                            </a>
                        </li>

                        <?php
                            }
                            ?>
                </ul>
            </li>
            <?php
                        }
                    }

            ?>



                <?php
    mysqli_close($link);

?>


    </ul>
</nav>

I would be very grateful if someone could tell me what the error is and why the div is not closing properly as I did not manage to locate the div wrongly closed.

    
asked by felipe andrade 03.09.2017 в 15:23
source

1 answer

2

The problem is in carusel.php and it happens because some div need to be closed. It is something that could be clearly seen if the code were indented in a more consistent way; Remember that a clean code is a code easier to maintain.

This is the code of your file, with a different indentation and comments where there are potential errors (although the problem is really only one of them):

<div id="myCarousel" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class=""></li>
        <li data-target="#myCarousel" data-slide-to="1" class=""></li>
        <li data-target="#myCarousel" data-slide-to="2" class="active"></li>
    </ol>
    <?php
        $link=conectar();
        $d1=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante1' "); 
        $d2=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante2' ");
        $d3=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante3' ");

        while($titulo=mysqli_fetch_array($d1)){   
    ?>
    <div class="carousel-inner" style="border-radius:15px;"> <!-- POSIBLE ERROR: ESTE DIV DEBERÍA ESTAR FUERA DEL WHILE PARA QUE NO SE ABRIESE CADA VEZ --> 
        <div class="carousel-item">
            <img class="first-slide" src="/noticias/img/formacion-1024x588.jpg" alt="First slide">
            <div class="container">
                <div class="carousel-caption d-none d-md-block text-left">
                    <h1><?php echo $titulo['titulo']; ?></h1>
                    <p><?php echo $titulo['dlarga'];?></p>
                    <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                </div>
            </div>
         </div>
    <!-- POSIBLE ERROR: AQUÍ TE FALTARÍA CERRAR EL DIV .carousel-inner -->        
    <?php 
        }
        while($titulo=mysqli_fetch_array($d2)){    
    ?>
    <div class="carousel-item">
        <img class="second-slide" src="/noticias/img/slide-1240x327.jpg" alt="Second slide">
        <div class="container">
            <div class="carousel-caption d-none d-md-block">
                <h1><?php echo $titulo['titulo']; ?></h1>
                <p><?php echo $titulo['dlarga'];?></p>
                <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
            </div>
        </div>
    </div>
    <?php 
        }
        while($titulo=mysqli_fetch_array($d3)){    
    ?>
    <div class="carousel-item active">
        <img class="third-slide" src="/noticias/img/prevencion-riesgos-laborales.jpg" alt="Third slide">
        <div class="container">
            <div class="carousel-caption d-none d-md-block text-right">
                <h1><?php echo $titulo['titulo']; ?></h1>
                <p><?php echo $titulo['dlarga'];?></p>
                <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
            </div>
        </div>
    </div>
</div> <!-- POSIBLE ERROR: CIERRE INNECESARIO DE UN DIV -->
    <?php 
        } 
    ?>

    <a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Anterior</span>
    </a>
    <a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Siguiente</span>
    </a>
</div>

The real problem is that the opening and closing of div with class carousel-inner should be outside the loops while (right now the opening is in the first loop while and the closes is in the last loop while so you will see errors, especially if the number of iterations is not the same in the two loops).

The solution would be to move those opening and closing out of the loops. Something like this:

<div id="myCarousel" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class=""></li>
        <li data-target="#myCarousel" data-slide-to="1" class=""></li>
        <li data-target="#myCarousel" data-slide-to="2" class="active"></li>
    </ol>

    <div class="carousel-inner" style="border-radius:15px;">
        <?php
        $link=conectar();
        $d1=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante1' "); 
        $d2=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante2' ");
        $d3=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante3' ");

        while($titulo=mysqli_fetch_array($d1)){   
        ?>
        <div class="carousel-item">
            <img class="first-slide" src="/noticias/img/formacion-1024x588.jpg" alt="First slide">
            <div class="container">
                <div class="carousel-caption d-none d-md-block text-left">
                    <h1><?php echo $titulo['titulo']; ?></h1>
                    <p><?php echo $titulo['dlarga'];?></p>
                    <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                </div>
            </div>
        </div>       
        <?php 
        }
        while($titulo=mysqli_fetch_array($d2)){    
        ?>
        <div class="carousel-item">
            <img class="second-slide" src="/noticias/img/slide-1240x327.jpg" alt="Second slide">
            <div class="container">
                <div class="carousel-caption d-none d-md-block">
                    <h1><?php echo $titulo['titulo']; ?></h1>
                    <p><?php echo $titulo['dlarga'];?></p>
                    <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                </div>
            </div>
        </div>
        <?php 
        }
        while($titulo=mysqli_fetch_array($d3)){    
        ?>
        <div class="carousel-item active">
            <img class="third-slide" src="/noticias/img/prevencion-riesgos-laborales.jpg" alt="Third slide">
            <div class="container">
                <div class="carousel-caption d-none d-md-block text-right">
                    <h1><?php echo $titulo['titulo']; ?></h1>
                    <p><?php echo $titulo['dlarga'];?></p>
                    <button class="btn btn-secondary" onclick="irnoti(<?php echo $titulo['id'];?>);" role="button"><span>Ver detalles</span></button>
                </div>
            </div>
        </div>
        <?php 
        } 
        ?>

    </div> <!-- cierre de carousel-inner -->

    <a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Anterior</span>
    </a>
    <a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Siguiente</span>
    </a>
</div>
    
answered by 03.09.2017 / 16:01
source