neobolt Posted April 17, 2013 Share Posted April 17, 2013 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']) = 26The 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 = 38Loop 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/>"; ?> Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted April 17, 2013 Solution Share Posted April 17, 2013 while($row = mysql_fetch_array($result)) { // Print out the contents of each row into a table $val = round(365/$row['Frequency']); echo "$val<br/><br/>"; $total += $val; } echo "$total<br/><br/>"; Quote Link to comment Share on other sites More sharing options...
neobolt Posted April 17, 2013 Author Share Posted April 17, 2013 Amazing, Works perfectly.Thank you very much for the help.I'm still trying to wrap my mind around loops. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.