Thursday, 19 September 2013

Setting up loops in a query and/or array

Setting up loops in a query and/or array

This may be my most advanced question yet. Using the stupid Hill climb
game to learn more mySql and php.
`$varVeh=$_POST['Veh_num'];
$sql_HiScores = "SELECT c.course_name as course, e.distance as distance,
e.score as score
from hc_entries e
left join hc_course c on e.course=c.course_num
WHERE e.vehicle=$varVeh
ORDER BY score DESC";
$result_HiScores = mysql_query($sql_HiScores);
echo "<table>";
while($row = mysql_fetch_array($result_HiScores))
{
echo "<tr>";
echo "<td>" .$row['course'] . "</td>";
echo "<td>" .$row['score'] . "</td>";
echo "<td>" .$row['distance'] . "</td>";
}
echo "</table>";`
I would get this table...
Best Scores for Jeep Course Score Distance Desert 123060 1825 Desert
105760 1661 Desert 86865 1499 Desert 79555 1375 Desert 64434 1254 Desert
53212 1157 Desert 52144 1201 Countryside 57890 1342 Countryside 48455 1303
Countryside 18770 888 Countryside 7275 519 Countryside 6555 525
So I want to get fancy :) and not sure how to do it.
Suppose I want to display the top 5 scores per course. So the last few
Desert is no longer displayed. Also there is a lot more courses as well.
Where would I begin on this?

No comments:

Post a Comment