Arcadia Posted March 17, 2015 Share Posted March 17, 2015 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); ?> 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 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
Archived
This topic is now archived and is closed to further replies.