Klance Posted April 14, 2008 Share Posted April 14, 2008 I want to display the highest score of a song from the db GHScores the table GH80 and the field Score. The field Score holds all the scores, how do I just pull out just the highest score? Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/ Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 ORDER BY `score` DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/#findComment-516890 Share on other sites More sharing options...
effigy Posted April 14, 2008 Share Posted April 14, 2008 SELECT MAX(field) FROM table Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/#findComment-516891 Share on other sites More sharing options...
unidox Posted April 14, 2008 Share Posted April 14, 2008 SELECT MAX(field) FROM table That will work. Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/#findComment-516896 Share on other sites More sharing options...
Klance Posted April 14, 2008 Author Share Posted April 14, 2008 Ok, I tried that and it came out with "Resource id #2" Heres the code I used: <?php $host = "localhost"; $user = "root"; $pass = "****"; $db = "GHScores"; $conn = mysql_connect($host, $user, $pass) or die("Unable to connect!") ; mysql_select_db($db) or die("Unable to select database!"); $query = "SELECT MAX(score) FROM GH80"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo $result ?> Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/#findComment-516921 Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 <?php $host = "localhost"; $user = "root"; $pass = "****"; $db = "GHScores"; $conn = mysql_connect($host, $user, $pass) or die("Unable to connect!") ; mysql_select_db($db) or die("Unable to select database!"); $query = "SELECT MAX(score) FROM GH80"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo mysql_result($result, 0); ?> Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/#findComment-516935 Share on other sites More sharing options...
Klance Posted April 14, 2008 Author Share Posted April 14, 2008 <?php $host = "localhost"; $user = "root"; $pass = "****"; $db = "GHScores"; $conn = mysql_connect($host, $user, $pass) or die("Unable to connect!") ; mysql_select_db($db) or die("Unable to select database!"); $query = "SELECT MAX(score) FROM GH80"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo mysql_result($result, 0); ?> Thank you Link to comment https://forums.phpfreaks.com/topic/101081-solved-how-do-i-pull-out-the-highest-value-in-mysql/#findComment-516939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.