Jackson Hogan
Jackson Hogan

Reputation: 83

displaying divs dynamically side by side php from database

I am trying to align to divs side by side dynamically so it will look something like this... enter image description here

Instead I am getting something like this...

enter image description here

Code...

<body>
    <div class="container">
        <?php 
        $sql = "SELECT id, name, price FROM tracylynn";
        $result = $db->query($sql);

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo '<div id="item">';
                    echo "test";
                echo '<div>';
            }
        }
        ?>
    </div>
</body>

.container {
width: 200px;
margin: 0 auto;
}

.container div{
border: 1px solid black;
float: left;
margin: 10px auto;
}

Upvotes: 0

Views: 827

Answers (1)

sanatsathyan
sanatsathyan

Reputation: 1763

You are not closing the div tag

if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            echo '<div id="item">';
                echo "test";
            echo '</div>';  //here
        }
    }

Upvotes: 4

Related Questions