php嵌套循环问题
代码如下:执行效果如图所示,似乎内层while没有真正循环,求高手提供解决方法~~<?phpinclude_once("functions/database.php");...
代码如下:执行效果如图所示,似乎内层while没有真正循环,求高手提供解决方法~~
<?php
include_once("functions/database.php");
getConnection();
$selectSQL="select COUNT(distinct stuNum) from grade";
$rowSet=mysql_query($selectSQL);
$selectSQL1="select distinct stuNum from grade order by stuNum";
$selectSQL2="select * from grade ";
$resultSet1=mysql_query($selectSQL1);
$resultSet2=mysql_query($selectSQL2);
while($student1=mysql_fetch_array($resultSet1)){
$sid=$student1['stuNum'];
$lession_cout=0;
$score_sum=0;
$average=0;
while($student2=mysql_fetch_array($resultSet2)){
$psid=$student2['stuNum'];
if($sid==$psid){
$lession_cout++;
$score_sum=$score_sum+$student2['coursGrade'];
}
else{
continue;
}
//$average=$score_sum/$lession_cout;
}
//$average=$score_sum/$lession_cout;
?>
<tr align="center">
<td height="21"><?php echo $sid; ?></td>
<td><?php echo $lession_cout; ?></td>
<td><?php echo $score_sum; ?></td>
<td><?php echo $average; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="21" colspan="4">考试总人数:<?php echo $rowSet?></td>
</tr>
</table>
</body>
<?php
closeConnection();
?> 展开
<?php
include_once("functions/database.php");
getConnection();
$selectSQL="select COUNT(distinct stuNum) from grade";
$rowSet=mysql_query($selectSQL);
$selectSQL1="select distinct stuNum from grade order by stuNum";
$selectSQL2="select * from grade ";
$resultSet1=mysql_query($selectSQL1);
$resultSet2=mysql_query($selectSQL2);
while($student1=mysql_fetch_array($resultSet1)){
$sid=$student1['stuNum'];
$lession_cout=0;
$score_sum=0;
$average=0;
while($student2=mysql_fetch_array($resultSet2)){
$psid=$student2['stuNum'];
if($sid==$psid){
$lession_cout++;
$score_sum=$score_sum+$student2['coursGrade'];
}
else{
continue;
}
//$average=$score_sum/$lession_cout;
}
//$average=$score_sum/$lession_cout;
?>
<tr align="center">
<td height="21"><?php echo $sid; ?></td>
<td><?php echo $lession_cout; ?></td>
<td><?php echo $score_sum; ?></td>
<td><?php echo $average; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="21" colspan="4">考试总人数:<?php echo $rowSet?></td>
</tr>
</table>
</body>
<?php
closeConnection();
?> 展开
展开全部
成绩表:学号 考试课程 分数
<?php
$selectSQL="select COUNT(distinct 学号) from 成绩表";
$rowSet=mysql_query($selectSQL);
$selectSQL1="select * from 成绩表 order by 学号";
$resultSet1=mysql_query($selectSQL1);
while($student1=mysql_fetch_accos($resultSet1)){
$sid=$student1['学号'];
$selectSQL2="select count(*) from 成绩表 where 学号=$sid";
$lession_cout=mysql_query($selectSQL2);
$selectSQL3="select 分数 from 成绩表 where 学号=$sid";
$resultSet3= $lession_cout=mysql_query($selectSQL3);
while($student3=mysql_fetch_accos($resultSet3)){
$score_sum= $score_sum + $student3[分数];
}
$average=$score_sum/$lession_cout;
}
?>
<tr align="center">
<td height="21"><?php echo $sid; ?></td>
<td><?php echo $lession_cout; ?></td>
<td><?php echo $score_sum; ?></td>
<td><?php echo $average; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="21" colspan="4">考试总人数:<?php echo $rowSet?></td>
</tr>
</table>
</body>
<?php
closeConnection();
?>
这样弄看行不?
<?php
$selectSQL="select COUNT(distinct 学号) from 成绩表";
$rowSet=mysql_query($selectSQL);
$selectSQL1="select * from 成绩表 order by 学号";
$resultSet1=mysql_query($selectSQL1);
while($student1=mysql_fetch_accos($resultSet1)){
$sid=$student1['学号'];
$selectSQL2="select count(*) from 成绩表 where 学号=$sid";
$lession_cout=mysql_query($selectSQL2);
$selectSQL3="select 分数 from 成绩表 where 学号=$sid";
$resultSet3= $lession_cout=mysql_query($selectSQL3);
while($student3=mysql_fetch_accos($resultSet3)){
$score_sum= $score_sum + $student3[分数];
}
$average=$score_sum/$lession_cout;
}
?>
<tr align="center">
<td height="21"><?php echo $sid; ?></td>
<td><?php echo $lession_cout; ?></td>
<td><?php echo $score_sum; ?></td>
<td><?php echo $average; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="21" colspan="4">考试总人数:<?php echo $rowSet?></td>
</tr>
</table>
</body>
<?php
closeConnection();
?>
这样弄看行不?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询