I have a query connected to a database and it works as designed but I feel like I have way more code then needed. Can someone help me out?
Basically I'm trying to get a sum of multiple columns and then assign a variable to the outcome. The variable has to be unique every time so I can echo them out later individually.
Would it be possible to use an array to select a different column and then use that same array to make the variables?
I hope it all makes sense what I'm trying to achieve.
This example is only 3 of the 12 queries I have.
$sql = ("SELECT SUM(Case_closed) AS sum_closed FROM production WHERE Datum = '$actual_time' AND jaar = '$year' ");
$result = mysqli_query($connect, $sql) ;
$Case_closed = $result->fetch_object()->sum_closed;
$sql = ("SELECT SUM(Case_handled) AS sum_handled FROM production WHERE Datum = '$actual_time' AND jaar = '$year' ");
$result = mysqli_query($connect, $sql) ;
$Case_handled = $result->fetch_object()->sum_handled;
$sql = ("SELECT SUM(swap) AS sum_swap FROM production WHERE Datum = '$actual_time' AND jaar = '$year' ");
$result = mysqli_query($connect, $sql) ;
$swap = $result->fetch_object()->sum_swap;