基本上我在foreach
循环中有一个foreach
循环。检索到的记录都显示正常。但是我希望limit
在我的第二个DESC LIMIT
循环中foreach
使用$get_records = $db->prepare("SELECT users.*, referrals.* FROM users
LEFT JOIN referrals ON users.user_id = referrals.referred_user
WHERE referrals.referred_by = :ref_by");
$get_records->bindParam(':ref_by', $global_user_id);
$get_records->execute();
$result_records = $get_records->fetchAll(PDO::FETCH_ASSOC);
if(count($result_records) > 0) {
foreach($result_records as $row) {
$ref_user_id = trim($row['user_id']);
$get_records2 = $db->prepare("SELECT users.*, referrals.* FROM users
LEFT JOIN referrals ON users.user_id = referrals.referred_user
WHERE referrals.referred_by = :ref_by ORDER BY referrals.referral_id DESC LIMIT 5");
$get_records2->bindParam(':ref_by', $ref_user_id);
$get_records2->execute();
$result_records2 = $get_records2->fetchAll(PDO::FETCH_ASSOC);
if(count($result_records2) > 0) {
foreach($result_records2 as $row) {
$ref_username = trim($row['username']);
$ref_email = trim($row['email']);
$ref_joined = trim($row['joined']);
?>
<div class="table-row">
<ul>
<li class="th-1"><?php echo $ref_username; ?></li>
<li class="th-2"><?php echo $ref_email; ?></li>
<li class="th-3"><?php echo $ref_joined; ?></li>
</ul>
</div>
<?php
}
}
}
}
进行记录。但它似乎不起作用。我没有收到任何错误。它只返回所有记录而不是指定的数量(5)。
这是我的代码。
Expression.And