Read up on some PHP and MySQL tutorials.
Here's a basic example:
// Connect to MySQL server first – You can use variables instead of these literals
$db = mysql_connect('localhost', 'username', 'password');
if (!$db) {
echo 'Could not connect to MySQL server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
// Select the database you want to use – You can use a variable here too instead
if (!mysql_select_db('DBname', $db)) { // Did selection fail?
// Handle error
echo 'DB Selection failed. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
$sql = "SELECT username, points FROM users ORDER BY points DESC LIMIT 10";
$result = mysql_query($sql, $db);
if (!$result) {
// Handle error
echo 'Query failed. SQL: ', $sql, '<br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
$cnt = (int) 0;
// The while loop stops when there's no data left; it might not even go in loop
// and echo anything when there's no data returned on the first call to
// mysql_fetch_assoc()
while($row = mysql_fetch_assoc($result)) { // Retrieve data until no more
echo 'Username: ', $row['username'], ' has ', $row['points'], '<br />';
$cnt++;
}
if (0 == $cnt)
echo 'No data found <br />';