0
Table with data:

id   score   inputid
1      1        1
2      4        1
3      3        1
4      1        2
5      2        2
6      3        5
7      1        6
8      1        6

while ($stmt_score->fetch())
{
 if($bind_inputid == '1') $array['score'][0] += $bind_score;
 if($bind_inputid == '2') $array['score'][1] += $bind_score;
 if($bind_inputid == '5') $array['score'][2] += $bind_score;
 if($bind_inputid == '6') $array['score'][3] += $bind_score;
}

上記のように、すべての結果を特定の ID で合計したいと考えています。しかし、より多くの $bind_inputid ID があるため、私の質問は、ID のより多くの結果に対して自動ステートメントを作成する方法です。

mysql select ではなく while ループで実行する必要があります。PHPラング。どうも。

4

1 に答える 1

1

結果が次のようにソートされているとしますinputid:

$inputid_curr = -1;
$score_array_index = -1;
while ($stmt_score->fetch())
{
 if($inputid_curr != $bind_inputid)
 {
  $score_array_index = $score_array_index + 1;
  $inputid_curr = $bind_inputid;
 }

 $array['score'][$score_array_index] += $bind_score;
}
于 2011-06-06T19:25:14.507 に答える