I did a little research in how I could total up the values of a column in MySQL and found that SELECT SUM was the best method, however I've spent hours trying to work this out and I still can't get it to work:
Here's the code:
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = mysqli_query('SELECT SUM(price) AS value_sum FROM xCarts_'. $useXsesh .'_sandwiches');
$row = mysqli_fetch_assoc($result);
$sum = $row['value_sum'];
echo $sum;
mysqli_close($conn);
Here's the table:
