Q:

Php echo makes divs joined

I'm trying to create a product catalog in php.
Here is the html flex-container:
<div class="products">
        <?php
        echo file_get_contents("http://192.168.64.2/CodeWay/Pages/product.php");
        ?>
        </div>

And this php code, takes all the existing courses from the database and echoes them to this container:
 require_once '../Backend/Config.php';
    $query = "SELECT * FROM `products` ORDER BY `product_id`";
    $result = $link->query($query);

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            echo "<div class='product-flex-item'>";
            echo $row["product_name"];
            echo "<div> <br>";
        }
}

But when it echoes the flex-items the flex-container looks like this:
<div class="products">
        <div class='product-flex-item'>php beginner course<div> <br><div class='product-flex-item'>cascca<div> <br></div>

And its not displaying correctly, the second one is smaller than the first one, and when i try to set justify content to space between, its doing nothing at all.

A:

Change echo "<div> <br>"; to echo "</div> <br>";
You are simply not closing the div you open, and they get nested into each other.

