$lmt='0,12';
if(isset($_GET['page'])&&($_GET['page']==2)){ $lmt='12,20';
}
// getting the most viewed blogs id
$resultcounter=mysqli_query($link, "select * from `entries` WHERE (published='1' and views >='20000') order by views ASC LIMIT ".$lmt);
while ($rowcounter = mysqli_fetch_array($resultcounter)) {
$thisblogid = $rowcounter['blogid'];
// set variable to count shown results
$shownresults = 0;
// begin while statement
while ($shownresults < 5) {
$resultsearch = mysqli_query($link, "select * from blogs WHERE id='$thisblogid' AND banned='0' AND active='1' AND title !='' ORDER BY id DESC LIMIT 0, 1");
while ($rowsearch = mysqli_fetch_array($resultsearch)) {
$thisblogname = $rowsearch['blogname'];
$thisauthorname = $rowsearch['authorname'];
$thistitle = $rowsearch['title'];
$thisviews = $rowsearch['views'];
$thisauthorimage = $rowsearch['authorimage'];
$thisaboutauthor = $rowsearch['aboutauthor'];
// set empty image placeholder
if ($thisauthorimage == "") {
$thisauthorimage = "no-author-image.png";
}
} // close blog info while statement
// increase shownreults value by one
$shownresults++;
} // end while statement ($shownresults<12)
?>