I'm am trying to retrieve top 3 recent posts in MySQL database and post them in separate DIV using for loop.
Each post should show only show first 300 characters.
However it shows only the first post (300 characters) in all three
DIV.
Here is the code:
<!--- HTML CODE HERE --!>
<?php
for($i = 1; $i<=3; $i++) {
?>
<div id="outer-box">
<div id="postImage-wrapper">
image
</div>
<div id="postContent-wrapper">
<h3> This is an Example post </h3>
<span id="postInfo-wrapper">Author | 22/10/2015 | Xbox | 3 Comments</span><br />
<?php
$result = doSql("SELECT `gamereviews`.`reviewContent` FROM `gamereviews` ORDER BY `gamereviews`.`dateOfReview` DESC LIMIT 3");
$row = mysqli_fetch_row($result);
echo '<div onclick="alert(\''.$row[0].'\');">'.substr($row[0], 0, 300).'</div>';
?>
<!-- <p class="post-snippet">Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived not only five centuries five centuries.</p> -->
</div>
<div id="postRating-wrapper">
7.7
</div>
</div>
<?php
}
?>
Here is the result: https://gyazo.com/5593b4a4ccd82b61e88e8af90dedbe2f
I realize that the problem is probably with my for loop, that is, it simply prints out the first post 3 times.
But what is the way around this, how can I retrieve 3 posts from database and print them out in each div using a for loop
or (if there is a better way)?