I have the following code to enter the positions, etc. I have two problems:
- The position numbers show like 1, 2, 2, 2, 2 instead of 1, 2, 3, 4, 5
- It would be "Days" even if the number of days is 1. I am uploading a screenshot.
Thank you very much for your input. https://postimg.cc/mhQHqqyk
if (isset($_GET['boardcount']) && is_numeric($_GET['boardcount']) && $_GET['boardcount'] > 0) {
$boardcount = $_GET['boardcount'];
} else {
$boardcount = 20;
}
$getleaderboard = lfmsql_query("SELECT a.days AS days, b.firstname AS firstname, b.lastname AS lastname, b.email AS email FROM `".$prefix."surftarget_logs` a LEFT JOIN `".$prefix."members` b ON (a.userid=b.Id) WHERE a.date='".$todaydate."' OR a.date='".$yesterdate."' ORDER BY a.days DESC") or die(lfmsql_error());
$position = 1;
$lastdays = 0;
$boardoutput = '';
while ($position <= $boardcount && $leaderlist = lfmsql_fetch_assoc($getleaderboard)) {
$gravatarimg = "https://www.gravatar.com/avatar/".md5($leaderlist['email'])."?d=mm";
if (isset($_GET['usetable']) && $_GET['usetable'] > 0) {
$boardoutput .= '<tr><td style="background-color:#15aa00; padding: 15px; width:360px; color:#fff; border:solid; border-width: 1px 0; border-color:#fff;">
<h5>#'.$position.' <img style="max-height:50px; max-width:50px;" src="'.$gravatarimg.'"> '.$leaderlist['firstname'].' '.$leaderlist['lastname'].'</h5>
<span>'.$leaderlist['days'].' days</span>
</td></tr>';
} else {
$boardoutput .= '<li style="background-color:#15aa00; color:#fff;">
<div >
<h5 >#'.$position.' <img style="max-height:50px; max-width:50px;" src="'.$gravatarimg.'"> '.$leaderlist['firstname'].' '.$leaderlist['lastname'].'</h5>
<p>'.$leaderlist['days'].' days</p>
</div>
</li>';
}
if ($leaderlist['days'] > $lastdays) {
$position = $position 1;
$lastdays = $leaderlist['days'];
}
}
CodePudding user response:
This seems to be a logical bug in your code. As per the screenshot, it appears that it is not going inside the if block the second time onwards. you have to keep >= under if condition if you really want to increment them.
Modify this code:-
if ($leaderlist['days'] > $lastdays) {
$position = $position 1;
$lastdays = $leaderlist['days'];
}
To:-
if ($leaderlist['days'] >= $lastdays) {
$position = $position 1;
$lastdays = $leaderlist['days'];
}
Note:- >= symbol.