You shouldn't have nested loops, that's creating a cross product between the two results, not processing them in parallel.
You should have a single loop that fetches a row from each query.
<?php
$stmt88 = $mysqli->prepare("SELECT naam,geld FROM `gebruikers` ORDER BY geld DESC LIMIT 10 ");
$stmt88->execute();
$result = $stmt88->get_result(); //only works when nd_mysli is set on the server!
$stmt88->close();
$stmt89 = $mysqli->prepare("SELECT naam,user_amountslapped FROM `gebruikers` ORDER BY user_amountslapped DESC LIMIT 10 ");
$stmt89->execute();
$result2 = $stmt89->get_result(); //only works when nd_mysli is set on the server!
$stmt89->close();
while (($rowrich = $result->fetch_assoc()) && ($rowrich2 = $result2->fetch_assoc())) {
?>
<tr><td >
<a class="online" href="profile.php?username=<?= htmlspecialchars($rowrich['naam']) ?>"><b><?= htmlspecialchars($rowrich['naam']) ?></b></a></td>
<td>🍌<?= htmlspecialchars(number_format($rowrich['geld'],0,",",".")) ?></td>
<td >
<a class="online" href="profile.php?username=<?= htmlspecialchars($rowrich2['naam']) ?>"><b><?= htmlspecialchars($rowrich2['naam']) ?></b></a></td>
<td>🍌<?= htmlspecialchars(number_format($rowrich2['user_amountslapped'],0,",",".")) ?></td>
</tr>
</tbody>
<? } ?></table><br>
Note that if either of the queries returns less than 10 rows, the table will stop at the shorter length. If you want the longer length, use ||
in the while
condition, and then check whether $rowrich
or $rowrich2
is empty before outputting those columns.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…