0

I tried very hard reading tutorials, but can't handle This. Im using foreach to display orders in table, but i need to sum coins value of this array and sort it by site value

foreach ($orders as $key => $order)

        <td><?php echo $order->Id;?></td>
            <td><?php echo $order->UserId;?></a></td>
            <td><?php echo $order->Coins;?></td>
            <td><?php echo $order->Site;?></td>

I wonder how i could group this orders in sql, becouse it needs to be grouped by User, and then by Site, and for every Site make sum of Coins

Szymon Sus
  • 75
  • 1
  • 6
  • Are you getting this data from a Database? – Ricardo Ortega Magaña Mar 05 '17 at 21:26
  • Yes im getting this data from Database – Szymon Sus Mar 05 '17 at 21:27
  • You can sort the query directly from the database, and group by orderID to sum de coins. Or create a temp variable with the table html, while you add the Coins in another variable, that way, right before the foreach loops, print the whole data, AND the total coins, once you already have that value in a column of your table, you can use Javascript, to sort by value any of the columns. – Ricardo Ortega Magaña Mar 05 '17 at 21:29

0 Answers0