問題
私が直面している問題は、expected_weight から動的に損失を差し引くことができないことです。playing_dates カウントが終了するまで expected_weight を変更したい。期待される出力を参照してください。前もって感謝します!
コード:
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)