我現在面臨的問題是我不能夠減去expected_weight動態的喪失。我希望expected_weight可以改變,直到play_dates計數完成。請參閱預期的輸出。提前致謝!
代碼:
echo "<pre>";
$benchmark = 96.5; //The first weight from which a person commits to lose their weight every week.
$lose = 10; //Percentage of how much they commit to lose
$lose_weight = ($benchmark/100)*$lose; //This gives how much they should lose every week to meet the target
while($row_teams = mysql_fetch_assoc($result_select_teams)){
echo" {<br />";
echo" benchmark ==> ".$benchmark." Kg<br />";
echo" loss% ==> ".$lose."%<br />";
echo" lose_weight ==> ".$lose_weight." Kg<br /><br />";
echo" my_teams ==> ".$row_teams['t_name']."<br /><br />";
$playing_dates = $row_teams['playing_dates'];
$playing_dates = explode('|', $playing_dates);
$date = date('Y');
$noofweighins = count($playing_dates);
echo" noofweighins ==> ".$noofweighins."<br /><br />";
$lose_atleast = round($lose_weight/$noofweighins, 2);
$expected_weight = 0;
for($k=0; $k<count($playing_dates);$k++){
$expected_weight = $benchmark - $lose_atleast;
if(substr($playing_dates[$k], -4)<=$date){
echo" my_playing_dates ==> ".$playing_dates[$k]." to lose ==> ".$lose_atleast."<br />";
echo" Expected weight ==> ".$expected_weight."<br /><br />";
}
}
echo" }<br />";
}
}
echo "</pre>";
輸出
benchmark ==> 96.5 Kg
loss% ==> 10%
lose_weight ==> 9.65 Kg
noofweighins ==> 10
my_playing_dates ==> 16/02/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 18/02/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 13/03/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 20/03/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 27/03/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 03/04/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 10/04/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 17/04/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 24/04/2013 to lose ==> 0.965
Expected weight ==> 95.535
my_playing_dates ==> 01/05/2013 to lose ==> 0.965
Expected weight ==> 95.535
期望輸出
benchmark ==> 96.5 Kg
loss% ==> 10%
lose_weight ==> 9.65 Kg
noofweighins ==> 10
my_playing_dates ==> 16/02/2013 to lose ==> 0.965
Expected weight ==> 95.535 (96.5 - 0.965)
my_playing_dates ==> 18/02/2013 to lose ==> 0.965
Expected weight ==> 94.57 (95.535 - 0.965)
my_playing_dates ==> 13/03/2013 to lose ==> 0.965
Expected weight ==> 93.605 (94.57 - 0.965)
my_playing_dates ==> 20/03/2013 to lose ==> 0.965
Expected weight ==> 92.64 (93.605 - 0.965)
my_playing_dates ==> 27/03/2013 to lose ==> 0.965
Expected weight ==> 91.675 (92.64 - 0.965)
my_playing_dates ==> 03/04/2013 to lose ==> 0.965
Expected weight ==> 90.71 (91.675 - 0.965)
my_playing_dates ==> 10/04/2013 to lose ==> 0.965
Expected weight ==> 89.745 (90.71 - 0.965)
my_playing_dates ==> 17/04/2013 to lose ==> 0.965
Expected weight ==> 88.78 (89.745 - 0.965)
my_playing_dates ==> 24/04/2013 to lose ==> 0.965
Expected weight ==> 87.815 (88.78 - 0.965)
my_playing_dates ==> 01/05/2013 to lose ==> 0.965
Expected weight ==> 86.85 (87.815 - 0.965)
嘿凱爾有一點改動,工程!非常感謝 – colourtheweb 2013-04-05 15:36:07
沒問題,很高興我能幫上忙。請你能+1這篇文章,我想建立一些代表:) – James 2013-04-05 15:42:20