I'd like to display results from two tables in my MYSQL database using the for each loop. Currently I have split both tables into two separate loops like this:
<?php
$i = 0;
foreach (array_reverse ($articles) as $article){?>
<div class="greyvertical midtopmargin item leftpadding rightpadding">
<a href="article.php?id=<?php echo $article['article_id']; ?>"><img src="../lifestyle/photos/articles/<?php echo $article['photo_folder']; ?>/<?php echo $article['photo_1']; ?>" alt="item">
<h5 class="whitetext text2 extrabold smalltoppadding leftpadding"><?php echo $article['article_title']; ?></h5></a>
<p class="meta whitetext leftpadding smalltoppadding">
<?php echo $article['article_summary']; ?></p>
<a href="article.php?id=<?php echo $article['article_id']; ?>" class="whitetext text2 mediumfont leftpadding midbottommargin">READ ME</a>
</div>
<?php if (++$i == 5) break;
} ?>
<?php
$i = 0;
foreach (array_reverse ($posts) as $post){?>
<div class="greyvertical midtopmargin item leftpadding rightpadding">
<a href="post.php?id=<?php echo $post['post_id']; ?>"><img src="../lifestyle/photos/blog/<?php echo $post['photo_folder']; ?>/<?php echo $post['photo_bg']; ?>" alt="item">
<h5 class="whitetext extrabold text2 leftpadding smalltoppadding"><?php echo $post['post_title']; ?></h5></a>
<p class="meta leftpadding whitetext smalltoppadding">
<?php echo $post['post_summary']; ?></p>
<a href="post.php?id=<?php echo $post['post_id']; ?>" class="whitetext text2 mediumfont leftpadding midbottommargin">READ ME</a>
</div>
<?php if (++$i == 5) break;
} ?>
As you can see they are almost identical with slight differences but I am completely stuck on how to combine the two without them being separate as it is now. Could anyone let me know in layman's terms how to combine the two loops into one? I.e I want to combine the articles and posts tables so they will be displayed as one rather than separately. thanks in advance guys.