gibbonuk Posted July 28, 2011 Share Posted July 28, 2011 Hi, just getting myself a little confused with somthing. I have the simple method of retrieving data from a mysql into an array, but as the values come i want to turn them into a percentage just before they go into the array, where can i do the calculation? The code for fetching the mysql data into array is: $request = "SELECT * FROM $table WHERE id BETWEEN $start_range AND $end_range"; $result = mysql_query($request) or die("Cannot get sql data"); $id=""; $value=""; while($row = mysql_fetch_array($result)){ //gather data from sql //$id[] = $row["id"]; $value[] = $row["value"]; } //save data into arrays $myData->addPoints($value,$table); $myData->setSerieDescription($table,"DataSet ".$i); can i just do the calculation here : $value[] = $row["value"]; ???? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243102-modifying-incoming-sql-data-into-array/ Share on other sites More sharing options...
Nodral Posted July 28, 2011 Share Posted July 28, 2011 What are they a percentage of? You can certainly do it the way you have stated. $value[] = "do calculation on" $row["value"]; This would create an array called $value containing all th %values in the same order as they were originally written int o th $row['value'] array Quote Link to comment https://forums.phpfreaks.com/topic/243102-modifying-incoming-sql-data-into-array/#findComment-1248544 Share on other sites More sharing options...
gibbonuk Posted July 28, 2011 Author Share Posted July 28, 2011 Thanks for confirming that. will give it ago. Andy Quote Link to comment https://forums.phpfreaks.com/topic/243102-modifying-incoming-sql-data-into-array/#findComment-1248568 Share on other sites More sharing options...
AbraCadaver Posted July 28, 2011 Share Posted July 28, 2011 You can also do: $request = "SELECT id, value*100 AS percent FROM $table WHERE id BETWEEN $start_range AND $end_range"; Then use $row['percent']. Quote Link to comment https://forums.phpfreaks.com/topic/243102-modifying-incoming-sql-data-into-array/#findComment-1248591 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.