w424637 Posted July 11, 2011 Share Posted July 11, 2011 I think I'm almost there but not quite getting it. I have a query - from this I run a loop to establish a running balance - daya to day cumulative total. I then want to store this as an array. and finally extract to a variable the smallest value in the entire array. Below is the rogue code!! $strQuery = "SELECT uspgi_reporting.race_date, date_conv.month2, sum(uspgi_reporting.handle) as handle, sum(uspgi_reporting.profit) as trading_profit FROM uspgi_reporting Inner Join date_conv ON uspgi_reporting.race_date = date_conv.actual_date Where 1 = 1 group by uspgi_reporting.race_date, date_conv.month2"; $result = mysql_query($strQuery) or die(mysql_error()); $row_result = mysql_fetch_assoc($result); $myArray = array(); while($row_result = mysql_fetch_assoc($result)) { $running_total+= $row_result['trading_profit']; $myArray[] = $running_total; } $minValue = min(array($myArray)); echo $minValue; Any help really appreciated Quote Link to comment https://forums.phpfreaks.com/topic/241710-populate-array-and-extract-min-value/ Share on other sites More sharing options...
w424637 Posted July 11, 2011 Author Share Posted July 11, 2011 Should anyone chance upon this I have resolved the problem. Below is the code I have changed. $myArray = array(); while($row_result = mysql_fetch_assoc($result)) { $running_total+= $row_result['trading_profit']; $myArray[] = $running_total; } echo min($myArray); Quote Link to comment https://forums.phpfreaks.com/topic/241710-populate-array-and-extract-min-value/#findComment-1241426 Share on other sites More sharing options...
Psycho Posted July 11, 2011 Share Posted July 11, 2011 You found the error before I finished my post, but do you need all the individual values in the array or do you just need the total and minimum? If you only need the total and minimum you can create a query to get those values instead of querying all of the values and doing calculations in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/241710-populate-array-and-extract-min-value/#findComment-1241434 Share on other sites More sharing options...
w424637 Posted July 11, 2011 Author Share Posted July 11, 2011 The query is going to run anyway - the values it creates are used for a chart. I needed the minimum value to provide the chart with a Yaxis minimum. thanks Simon Quote Link to comment https://forums.phpfreaks.com/topic/241710-populate-array-and-extract-min-value/#findComment-1241436 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.