0

更新 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

ご不明な点がございましたら、お知らせください。

ありがとう

4

2 に答える 2

0

いくつかの手順に従う必要があります。

1) 結果をスコア (差分) で並べ替え、スコアが最も低い 6 つのレコードの ID を取得します。

$sql4 = "SELECT * FROM rounds WHERE userID='$userID' ORDER BY differential LIMIT 20";
$result4 = mysql_query($sql4) or die(mysql_error());
$total_rounds = mysql_num_rows($result4);

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

$idsArray = array();
for($i=0; $i<$score_count; $i++){
    $dets = mysql_fetch_array($result4);
    $idsArray[] = $dets['roundID'];
}

2) レコードをループし、最初のステップで作成した配列の ID と一致させます。ID が一致する場合は CSS を適用し、それ以外の場合は適用しません。

$sql4 = "SELECT * FROM rounds WHERE userID='$userID' ORDER BY date DESC LIMIT 20";
$result4 = mysql_query($sql4) or die(mysql_error());

while($dets = mysql_fetch_array($result4)){
    if(in_array($dets['roundID'], $idsArray)){
        //apply CSS
        //display details here
    }
    else{
        //display details here
    }
}

注: mysql_* の使用を今すぐ停止する必要があります。専門家は、代わりに mysqli_* を使用することを強く推奨しています

于 2013-01-09T06:42:27.923 に答える
0

私はあなたの$total_rounds = 16私の例を取り上げます$score_count would be 6

$total_rounds = 16;
$score_count = 6 // comes from the if-else loop you already have

// now we loop over the result
// the css is applied to every odd result, until $score_count is not 0

$counter = 0;
while( ( $data = mysql_fetch_assoc( $result4 ) ) !== false ) {
    if( ( $counter % 2 ) && $score_count ) {
        echo $data['date']; // apply your css here
    } else {
        echo $data['date'];
    }
    $counter++;
    $score_count--;

}

お役に立てれば。

于 2013-01-09T06:16:49.787 に答える