building ranking system with data from the database
<p>I am building a ranking system that takes data(totals) from the database and ranks them from the highest to the lowest.Here is the code:</p>

<pre><code>$data = array(
  'A'=&gt;19,'B'=&gt;18,'C'=&gt;17,'D'=&gt;17,'E'=&gt;16,'F'=&gt;15
);
//Populate the arrays with data from mysql
/*
--
-- Table structure for table `data`
--

CREATE TABLE IF NOT EXISTS `data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `totals` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=501 ;

--
-- Dumping data for table `data`
--

INSERT INTO `data` (`id`, `totals`) VALUES
(1, 468),
(2, 450),
(3, 400),
(4, 419),
(5, 400),
(6, 400),
(7, 500),
(8, 489),
(9, 412),
(10, 385);

*/
$rank = 0;
$lastScore = PHP_INT_MAX;
foreach( $data as $name=&gt;$score ) {
  if ( $lastScore !== $score ) {
    $lastScore = $score;
    $rank += 1;
  }
  printf("%s %d (%d)\n", $name, $score, $rank);
}
</code></pre>

<p>I want a way to populate the variable($data) with the values stored in the database,how can i do that?.</p>
