更新 2 (プレーヤーのハンディキャップ インデックスの計算)
$sql3 = "SELECT roundID FROM rounds WHERE userID='$userID'";
$result3 = mysql_query($sql3) or die(mysql_error());
$total_rounds = mysql_num_rows($result3);
//CALCULATE USER HANDICAP INDEX IF TOTAL_ROUNDS > 4
if($total_rounds > 4){
if($total_rounds<7) { $score_count = 1; }
elseif($total_rounds<9) { $score_count = 2; }
elseif($total_rounds<11) { $score_count = 3; }
elseif($total_rounds<13) { $score_count = 4; }
elseif($total_rounds<15) { $score_count = 5; }
elseif($total_rounds<17) { $score_count = 6; }
elseif($total_rounds<18) { $score_count = 7; }
elseif($total_rounds<19) { $score_count = 8; }
elseif($total_rounds<20) { $score_count = 9; }
else { $score_count = 10; }
$sql2 = "SELECT differential FROM rounds WHERE userID='$userID' ORDER BY date DESC LIMIT 20";
$result2 = mysql_query($sql2) or die(mysql_error());
$diff_results = array();
while($row = mysql_fetch_assoc($result2)){
$diff_results[] = $row['differential'];
}
sort($diff_results);
$diff_results = array_slice($diff_results, 0, $score_count);
$handicapIndex = array_sum($diff_results) / $score_count * 0.96;
$handicapIndex = (floor($handicapIndex * 10)) / 10;
うまくいけば、これでプレーヤーのハンディキャップ インデックスの計算方法がすべて理解できると思います。ここで、プレーヤー (ユーザー) に、インデックスの計算に使用されるラウンド (注文日) を表示したいと思います。
いつも感謝!
UPDATE (ラウンド テーブルの構造)
roundID - auto incrementing primary key
userID - INT
courseID - INT
tee - VARCHAR
differential - FLOAT
date - DATE
実装しようとしているこの機能を使い始めるのに苦労しています。どんな助けでも大歓迎です。
フィールド差分でソートしたい一連のmysql db結果があります。次のようにデータベースから引き出します。
$sql4 = "SELECT * FROM rounds WHERE userID='$userID' ORDER BY date DESC LIMIT 20";
$result4 = mysql_query($sql4) or die(mysql_error());
$total_rounds = mysql_num_rows($result4);
上記のように、返された行を数えて、この if-elseif-else ステートメントを実行し、異なる css で強調表示する必要があるスコアの数を割り出しました。
if($total_rounds<7) { $score_count = 1; }
elseif($total_rounds<9) { $score_count = 2; }
elseif($total_rounds<11) { $score_count = 3; }
elseif($total_rounds<13) { $score_count = 4; }
elseif($total_rounds<15) { $score_count = 5; }
elseif($total_rounds<17) { $score_count = 6; }
elseif($total_rounds<18) { $score_count = 7; }
elseif($total_rounds<19) { $score_count = 8; }
elseif($total_rounds<20) { $score_count = 9; }
else { $score_count = 10; }
たとえば、$total_rounds = 16 の場合、私の $score_count は 6 になります。ここで、この 16 行のデータ セットを取得し、php で吐き出す必要があるため、計算された 6 に別の CSS 形式を適用しながら、ORDER BY 日付を維持します。上記の if-elseif-else ステートメント。$score_count が計算されるのは、日付の順序を維持しながら、16 行のデータ セットの 6 つの最低スコアを強調表示する (別の CSS を適用する) 必要があるためです。
目的の出力は次のようになります (* は個別の css 形式を示します *)。
2013 年 1 月 8 日 - 16
2012 年 1 月 7 日 - 1 *
2013 年 1 月 6 日 - 15
2012 年 1 月 5 日 - 2 *
2013 年 1 月 4 日 - 14
2012 年 1 月 3 日 - 3 *
2013 年 1 月 2 日 - 13
2012 年 1 月 1 日 - 4 *
2012 年 12 月 31 日 - 12
2012 年 12 月 30 日 - 5 *
2012 年 12 月 29 日 - 11
2012 年 12 月 28 日 - 6 *
2012 年 12 月 27 日 - 10
2012 年 12 月 26 日 - 9
2012 年 12 月 25 日 - 8
2012 年 12 月 24 日 - 7
ご不明な点がございましたら、お知らせください。
ありがとう