Jump to content

Adding Values from an array (Not Sum Select)


neobolt
Go to solution Solved by Barand,

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/>";
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.