The code will look as follow:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$xAnswer = 0;
$yAnswer = 0;
$zAnswer = 0;
$result = mysql_query("SELECT x,y,z FROM MathTable");
while($row = mysql_fetch_array($result))
{
$xAnswer = Add($row["x"],$row["y"]);
$yAnswer = Multiply($row["z"],$row["y"]);
$zAnswer = Subtract($row["z"],$row["x"]);
}
mysql_close($con);
function Add($x,$y)
{
return $x + $y;
}
function Subtract($x,$y)
{
return $x-$y;
}
function Multiply($x,$y)
{
return $x*$y;
}
function Divide($x,$y)
{
return $x/$y;
}
?>
Alternatively one can handle the math in the sql as well as follow and then just pull the answers into a variable:
SELECT (x+y) AS Add,(x-y) AS Subtract,(z/x) AS Divide FROM MathTable
The the loop through the recordsset will be as follow
while($row = mysql_fetch_array($result))
{
$xAnswer = $row["Add"];
$yAnswer = $row["Subtract"];
$zAnswer = $row["Divide "];
}
Remember that the variables will have a different answer everytime the loop increments because of the amount of records in the table so you might want a running total or alternatively you can keep running total inside using the above Add example variables:
$xAnswer = $xAnswer + $row["Add"];