Arcadia Posted March 17, 2015 Share Posted March 17, 2015 (edited) I made a database in MySQL and made a database connection true php to show the data on the browser and it all works fine but the problem start when I only want show the top 10 highest score. I tried $result = mysql_query("SELECT top 10 ID, Naam, sum(Score) FROM Scores"); But it does not work it does really noting:( Below is my code. <?php $username = "root"; $password = ""; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("Oefentoets1",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT ID, Naam, Score FROM Scores"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "ID: ".$row{'ID'}. " Naam: ".$row{'Naam'}." Score: ". //display the results $row{'Score'}."<br>"; } //close the connection mysql_close($dbhandle); ?> Edited March 17, 2015 by Arcadia Quote Link to comment https://forums.phpfreaks.com/topic/295304-problem-showing-top-10-highest-score/ Share on other sites More sharing options...
PravinS Posted March 17, 2015 Share Posted March 17, 2015 SELECT TOP is not supported in MySQL, you need to use LIMIT try this SELECT ID, Name, Score FROM Scores ORDER BY Score DESC LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/295304-problem-showing-top-10-highest-score/#findComment-1508282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.