<?php
error_reporting(E_ALL^E_NOTICE);

//------------------------------------------------------------------------------
function cp(	// compara puntajes
	$a, $b	// valores: mixed, mixed
	)	// : int
{
	if ($a[1] == $b[1])
		return 0;
	return ($a[1] > $b[1]) ? -1 : 1;
}
?>
<html>
	<head></head>
	<style type="text/css">
*
{
	margin: 0;
	padding: 0;
	border: 0;
}

body
{
	font-family: Arial;
	font-size: 25px;
	background-color: #CCC;
	text-align: center;
}

table
{
	margin: 20px 0 0 0;
	width: 100%;
}

td
{
	border-bottom: #AAA 1px dotted;
}

td.right
{
	text-align: right;
}
	</style>
	<body>
		<p>HIGHSCORES</p>
		<table cellspacing="0" cellpadding="0">
<?php
$b = mysql_connect('XXX', 'XXX', 'XXX');	// data base
if (!$b)
	die('Could not connect to MySQL: '.mysql_error());

if (!mysql_select_db('XXX'))
	die('Could not select data base: '.mysql_error());

$r = mysql_query('SELECT * FROM jewels');	// results
if (!$r)
	die('Invalid query: '.mysql_error());

$p = array();	// scores
while ($f = mysql_fetch_assoc($r))	// row
	array_push($p, array($f['name'], $f['score']));
usort($p, 'cp');

foreach ($p as $i => $v):	// i: index, v: value
?>
			<tr>
				<td><?php echo $i+1, '.&nbsp;', $v[0], '&nbsp;' ?></td>
				<td class="right"><?php echo $v[1] ?></td>
			</tr>
<?php
endforeach;

mysql_free_result($r);
mysql_close($b);
?>
		</table>
	</body>
</html>