*************************************************CODE*****************************************************
<?php
include("config.php");
$chapter=5;
for ($i=1;$i<=$chapter;$i++){
$sql="SELECT MAX(score) AS maxscore FROM exercise_score WHERE chapter='$i'";
$query=mysql_query($sql);
$result=mysql_fetch_array($query);
$max=$result['maxscore'];
$sql2="SELECT * FROM exercise_score WHERE score='$max' AND chapter='$i' ";
$result2=mysql_query($sql2);