title: php code to give the position according to their scores (1st, 2nd, 3rd, 3rd, 5th)
body: <pre><code>CREATE TABLE IF NOT EXISTS `jss1_prelim` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `term` varchar(30) NOT NULL,
  `idnumber` varchar(30) NOT NULL,
  `subject` varchar(30) NOT NULL,
  `score` varchar(30) NOT NULL,
  `teacher` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
  )   ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
  
  INSERT INTO `jss1_prelim` (`id`, `term`, `idnumber`, `subject`, `score`, `teacher`)
  VALUES
  (1, 'Prelim', 'SBI-JS202', 'Computer', '82', 'TID273'),
  (2, 'Prelim', 'SBI-JS645', 'Computer', '63', 'TID273'),
  (3, 'Prelim', 'SBI-JS300', 'Computer', '65', 'TID273'),
  (4, 'Prelim', 'SBI-JS202', 'Igbo', '70', 'TID015'),
  (5, 'Prelim', 'SBI-JS645', 'Igbo', '65', 'TID015');
  </code></pre>
  
  <p>I need help on this script, This script works fine for sorting sql database entries. But I need php code to give the position according to their scores (1st, 2nd, 3rd, 3rd, 5th).</p>
  
  <pre><code>&lt;table border = '2'&gt;
  &lt;tr&gt;
  &lt;td&gt;Student ID&lt;/td&gt;
  &lt;td&gt;Score&lt;/td&gt;
  &lt;td&gt;Position&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
  
  $con = mysql_connect("localhost", "root", "");
  if(!$con)
  {
      echo "Could not establish connection to the database " . mysql_error();
  }
  
  $mydb = mysql_select_db("sbicenugu", $con);
  if (!$mydb)
  {
      echo "Error selecting database " . mysql_error();
  }
  
  $mystatement = mysql_query("SELECT * FROM jss1_prelim ORDER BY score DESC");
  $dbcount = mysql_num_rows($mystatement);
  $selection = array(0 =&gt; "");
  $nameselection = array(0 =&gt; "");
  
  $i = 0; 
      while ($row = mysql_fetch_array($mystatement))
      {
      $selection[$i] = $row['score'];
      $nameselection[$i] = $row['idnumber'];
      $i++; 
      }
  arsort($selection);
  ksort($nameselection);
  
  for ($x = 0; $x &lt; $dbcount; $x++)
  {
  echo "&lt;tr&gt; &lt;td&gt;$nameselection[$x]&lt;/td&gt; 
  &lt;td&gt;$selection[$x]&lt;/td&gt;
  &lt;td&gt;"; $grades = array($selection[$x]);
  $occurrences = array_count_values($grades);
  $grades = array_unique($grades);
  foreach($grades as $grade) 
  {
  if($grade == end($grades))$i += $occurrences[$grade]-1;
  echo str_repeat('-'.($i + 1).'&lt;br&gt;',$occurrences[$grade]);
  $i+= $occurrences[$grade];
  }
  echo"&lt;/td&gt; 
  &lt;/tr&gt;"; 
  }
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>This scripts was not giving me what i expected for the position of the student in class. also it gives different value position for those that their score are desame.
  I need help for this. </p>