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结果自动生成语句?
它必须在while循环中完成,而不是mysql select。PHP Lang.谢谢。
发布于 2011-06-07 03:25:15
假设您的结果是按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;
}https://stackoverflow.com/questions/6256896
复制相似问题