MrChillax MrChillax - 1 year ago 60
HTML Question

Add line break after 2 database rows PHP

I am trying to make a page where multiple items are being pulled from a database and showed on the site. I would like to add a line break after every 2 rows that are received from the database so it shows correctly.

I tried alot and did alot of research but it still doesn't work. Anybody got an idea what i'm doing wrong?

$con = mysql_connect("localhost","article_user","mypassword");

if (!$con)
die('Could not connect: ' . mysql_error());

mysql_select_db("articles", $con);

$query = "SELECT * FROM `Articles`";
$select_projects = mysql_query($query);


if (mysql_num_rows($select_projects) > 0) {
while($row = mysql_fetch_assoc($select_projects)) {
echo '<div class="col-md-6 related-post-block">';
echo '<div class="related-img"> <img src="file-upload/server/php/files/'.$row['image'].'" class="" alt></a> </div>';
echo '<h3>'.$row['header'].'</a></h3>';
echo '<p>'.$row['text'].'</p>';
echo '</div>';

if ($xi % 2 == 0)
echo '<br />';




Answer Source

You don't need another element to change the appearance, this should be fixed with css. Probably something like:

.related-post-block {
    margin-bottom: 15px;

Or if you want to inline it (which I don't recommend):

echo '<div class="col-md-6 related-post-block" style="margin-bottom: 15px">';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download