Answer the question
In order to leave comments, you need to log in
Where am I making a mistake in the WHILE loop?
Hello. There are 2 requests. One for a specific user, and the other for a whole array of users. The first code example that I will give is for 1 user and it works fine. That is, he counts and sums up all his things. And the second code is almost the same, it doesn't count. Displays only 1 item and its cost.
////////СЧИТАЕМ СКОЛЬКО ДЕНЕГ ВЕЩАМИ У КАЖДОГО ИГРОКА!
$totalitemoney = 0;
$itemid = mysqli_query($connect,"SELECT * FROM `items` LEFT OUTER JOIN `items_info` ON `items`.`item_id` = `items_info`.`id` WHERE `user_id`=36454");
while($moneyitemuser = mysqli_fetch_assoc($itemid)){
$totalitemoney = $totalitemoney + $moneyitemuser[price];
}
$totalmoneytopuser = 0;
while($usersall = mysqli_fetch_assoc($userall)){
if ($usersall[ban_chat] == 0) {$usersban='<span class="label label-success label-pill">NO</span>';}
if ($usersall[ban_chat] == 1) {$usersban='<span class="label label- label-pill">YES</span>';}
$topusersitemss = mysqli_query($connect,"SELECT * FROM `items` LEFT OUTER JOIN `items_info` ON `items`.`item_id` = `items_info`.`id` WHERE `user_id`='$usersall[id]'");
$topusersitems = mysqli_fetch_assoc($topusersitemss);
$totalmoneytopuser = $totalmoneytopuser + $topusersitems[price];
echo "
<tbody>
<tr>
<td>$usersall[id]</td>
<td><img src='$usersall[avatar]' alt='user' width='30'> <a href='./dice.php?tag=$usersall[id]'>$usersall[username]</a></td>
<td>$usersall[money]</td>
<td>$totalmoneytopuser</td>
<td>$usersall[created_at]</td>
<td>$usersban</td>
</tr>
</tbody>
";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question