-1
I’m trying problems in my code, I wanted him to get the 5 best players who most purchased products in the month, the problem is that I wanted him to catch the guy’s user and show the amount he paid, if he had more purchases, he would just add up the amount.
I tried to :
public function topShopping()
{
$stmt = $this->pdo->prepare("SELECT * FROM `website_transactions` ORDER BY `transaction_AMOUNT` DESC LIMIT 5");
$stmt->execute();
if($stmt->rowCount() == 0) { return "<div class=\"col-md-12\">
<div class=\"compra\" onclick=\"\">
<img class=\"imgboder\" src=\"https://minotar.net/avatar/steve/60\">
<p><b>NENHUMA COMPRA REGISTRADA</b></p>
</div>
</div>"; }
$fetch = $stmt->fetchAll(\PDO::FETCH_OBJ);
$return = "";
foreach ($fetch as $key => $rs)
{
$posicao = $key + 1;
$name = $rs->transaction_USERNAME;
$valor = $rs->transaction_AMOUNT;
$date = \DateTime::createFromFormat('Y-m-d', $rs->transaction_DATE)->format('Y/m/d');
$return .= "<b>
<tr class=\"tr\" style=\"border-radius: 10px;white-space: nowrap;\">
<td class=\"th\">$posicao</td>
<td class=\"th\"><img style=\"vertical-align: sub;width:20px!important;height:20px!important;border-radius: 3px;\" src=\"https://minotar.net/avatar/$name/100\"> $name <i class=\"fas fa-crown\"></i></td>
<td class=\"th\">R$ $valor</td>
</tr></b>";
}
return "{$return}";
}
wanted to know if I can put to add the value after several purchases with the same user
did not work error: http://prntscr.com/ozup1h
– Matheus Ferreira
I arranged the column name in the grouping and edited the answer
– Bins
vlw brother, I got it here
– Matheus Ferreira