php - Display 3 articles in same line with bootstrap

Im using php and mysqli database, I know how to pull information but it always put articles one bellow another:
Article 1
Article 2
Article 3
Insted of Article1, Article2, Article3
<section class="politique container">
<?php
$query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";
$result=mysqli_query($dbo, $query);
while($row=mysqli_fetch_array($result))
{
echo'<article>';
echo '<div class="container">';
echo '<div class="row padding>';
echo'<div class="col-md-12 ">';
echo '<div class="card col-md-4">';
echo '<img class="card-img-top" src="' . UPLPATH . $row['slika'] . '">';
echo '<div class="card-body">';
echo '<h6 class="card-title">';
echo $row['naslov'];
echo '</h6>';
echo '</div>';
echo'<div class="ispod">';
echo $row['datum'];
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo'</article>';
}?>
</section>
I included in condition only 3 articles per line but somehow it probably enters new container every time so that articles are bellow one of another.
Answer
Solution:
Move thewhile
loop so it happens WITHIN the row element.
<section class="politique container">
<?php
$query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";
$result=mysqli_query($dbo, $query);
echo'<article>';
echo '<div class="container">';
echo '<div class="row padding>';
while($row=mysqli_fetch_array($result)) {
echo '<div class="card col-md-4">';
echo '<img class="card-img-top" src="' . UPLPATH . $row['slika'] . '">';
echo '<div class="card-body">';
echo '<h6 class="card-title">';
echo $row['naslov'];
echo '</h6>';
echo '</div>';
echo'<div class="ispod">';
echo $row['datum'];
echo '</div>';
echo '</div>';
}
echo '</div>';
echo '</div>';
echo'</article>';
?>
</section>
Additionally, as mentioned in the comments on your question, there is a cleaner way to mix php and html in your code;
<?php
$query="SELECT*FROM projekt WHERE arhiva=0 AND kategorija='politique' LIMIT 3";
$result=mysqli_query($dbo, $query);
?>
<section class="politique container">
<article>
<div class="container">
<div class="row padding">
<?php while ($row = mysqli_fetch_array($result)) { ?>
<div class="card col-md-4">
<img class="card-img-top" src="<?php echo UPLPATH.$row['slika'] ?>">
<div class="card-body">
<h6 class="card-title"><?php echo $row['naslov']; ?></h6>
</div>
<div class="ispod">
<?php echo $row['datum']; ?>
</div>
</div>
<?php } ?>
</div>
</div>
</article>
</section>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: property [id] does not exist on this collection instance.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.