anonymous
2009-09-01 03:56:48 UTC
I know it sounds confusing... For PHP and MySQL programmers, I will give the code to do this in PHP and MySQL, but then I need a way to do the same thing in Excel.
include 'connect.php';
$record = "1";
$query = "SELECT ticket_cost FROM holidayBookings WHERE `link-to-master-record` = '$record'";
$query = mysql_query($query);
$totalAvCost = 0; //Average cost of Whole family holiday per ticket
while($records = mysql_fetch_array($query)) {
list($ticketCost) = $records;
$totalAvCost = $totalAvCost + (int)$ticketCost;
}
$totalAmountOfRecords = mysql_num_rows($query);
$totalAmountOfRecords = (int)$totalAmountOfRecords;
$totalAvCost = $totalAvCost / $totalAmountOfRecords;
$totalAvCost = ceil($totalAvCost); //Not neccessary - just to make sure it is rounded to whole number, not neccessary for excel (i can just format the cell)
echo "Your Average cost per ticket is: £ $totalAvCost";
mysql_close($connection);
?>
Well, I hope that makes it clearer for PHP and MySQL programmers. Unfortunately, I can't use VBA for this or else it would be easier.
Thanks in advance.