Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Adding Values from an array (Not Sum Select)

$
0
0

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/>";
?>

Viewing all articles
Browse latest Browse all 13200

Trending Articles