Forum Moderators: coopster
I'm trying to get a function called, where it adds up all the total costs from the table. Below is the code:
<?php
function get_total_price()
{
//sum total price for all items in inventory
$query = "select SUM(inventory.price*inventory.qty) AS subtotal, SUM(subtotal) AS total FROM inventory";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
return $row['total'];
}
?>
Here is the code to call the function:
<?
require('calculation.php');
$result = get_total_price();
?>
<?
$alltotal = $row['total'];
echo '<div id ="title">Total Earned for the day: $'.$alltotal.'</div>';
?>
When i execute the script, it gives me an error where it says Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\website1\calculation.php on line 12. I deleted 'SUM(subtotal) AS total', and it didnt give me any errors but it only shows a blank page.