The following code gives me the following:
$getexpenses = "SELECT sum(expense_amount) FROM projects_expense WHERE project_id=$project_id";
$showexpenses = @mysqli_query ($dbc, $getexpenses); // Run the query.
echo ' . $showexpenses . ';
Gives me a result of
' . $showexpenses . '
instead of the actual sum…
I’m sure it’s something simple I’m missing… thanks!
I added a call to
mysqli_fetch_assoc($showexpenses)to make it fully functional.I also sanitized
$project_idto avoid injections and used an alias to make the sum accessible through an associative array.We could also have used
mysqli_fetch_rowlike this:The alias is not needed anymore since we know the first column (0) is a match.
NB: you probably also need to
GROUP BY project_idif you want to useSUM()