Jump to content

Populate array and extract MIN value


w424637

Recommended Posts

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

 

 

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

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.