Jump to content

Adding Values from an array (Not Sum Select)


neobolt

Recommended Posts

Hello,

What I am trying to accomplish:
I have a table with values. I run a Select and create an array.
I would like to make my script take the number 365(days) and divide by the value in the table(frequency).
So lets say Frequency[0] is 14, the variable $total would become round(365/$row['Frequency']) = 26
The script would then loop and add the next value to the variable.
Frequency[1] is 30, variable $total becomes 26 + (365/$row['Frequency']) = 26 +12 = 38
Loop would continue until all the frequency values are complete.

Currently the script outputs each value individually, I need to make each value go through the division process then add together.
Any help or direction is appreciated. Thanks.

// Get all the data from the "mss" table
$result = mysql_query("SELECT * FROM mss") 
or die(mysql_error());

include("header.php");
echo "<br/>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
	// Print out the contents of each row into a table
$total = round(365/$row['Frequency']);
	echo "$total<br/><br/>";
} 

echo "$total<br/><br/>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.