Hello, i wrote a query which should sum all prices of the categories and group them by category.
$query = "SELECT SUM(price) FROM costs GROUP BY category";
The idea is to later then put every sum of each category in a variable that i can show on that category’s page.
Can someone help me with this code cuz it’s the first time for me doing this.
He is going to show it on the category page. Means he needs the data for a single category only and thus no aggregation.
From years of answering questions I learned that you have to always read between the lines. Or, rather, all the lines diligently. The described business case often contradicts with a question that was asked
thx for the replies guys, I searched and experimented a bit and came up with this:
$get_total = "SELECT SUM(price) as total FROM costs WHERE userid='$session_id' AND category='$category'";
if ($results = mysqli_query($conn, $get_total)) {
$show_s = mysqli_fetch_assoc($results);
$total = $show_s['total'];
}
This works perfect atm so i’m using this for my categories.