I made page with all profiles. Every 3 rows I inserting a Premium block between results. I have 12 rows on page and 4 premium blocks between every 3 rows. I need to show random users with premium='1' row from mysql every foreach loop.
$sth = $db->prepare("SELECT count(*) as premiumCount FROM users WHERE premium='1'");
$sth->execute();
$answer = $sth->fetch();
$premium = $answer['premiumCount'];
$sth2 = $db->prepare("SELECT * FROM users WHERE active='1' AND block='0' ORDER BY premium DESC LIMIT 12");
$sth2->execute();
$result = $sth2->fetchAll();
foreach ($results as $answer) {
// getting user info
if ($premium > 0) {
$sth = $db->prepare("SELECT * FROM users WHERE premium='1' ORDER BY RAND()");
// getting premium user info
}
}
This code is work, but it can be 2-3 same premium blocks on page (I need 4 different blocks).