Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have record of student by which i need to count first top 10 students.how can i retrive this type of record from mysql database

PHP
<?php
include("config.php");

$total = "select Total from student";
$x= mysql_query($total);

while($t = mysql_fetch_array($x))
{
    $numbers[] =$t['Total'];

    function maxN(array $numbers, $n)
    {
        $maxHeap = new SplMaxHeap;
        foreach($numbers as $number)
        {
            $maxHeap->insert($number);
        }
        return iterator_to_array(new LimitIterator($maxHeap, 0, $n));
    }
    print_r( maxN( $numbers, 10 ) );

}


//print_r( maxN( array(7,54,2,4,26,7,82,4,34,99,21,67), 4 ) );

$merit = "select merit from student";
$result = mysql_query($merit);

while($raw = mysql_fetch_array($result))
{

}

?>
Posted

1 solution

MySql has a LIMIT clause you can use. For example something like
PHP
$total = "select Total from student order by total limit 0,9";

FOr more info, see 13.2.9 SELECT Syntax[^]
 
Share this answer
 
Comments
Member 10011989 19-Sep-15 3:37am    
thanks mika this will only gives fisrt 10 record of my database bt i want record from whole table not only first 10 tuple
Wendelius 19-Sep-15 4:23am    
I'm sorry but I don't understand your question. The limit controls how many records are returned and the order by controls the ordering before limit.

Is the ordering the question or something else?
Member 10011989 19-Sep-15 4:50am    
if i have values like total marks of HHc and SSc out of 1000 are 340,333,544,678,789,987,256,543,674
then i need to count topers from their total marks
Wendelius 19-Sep-15 4:53am    
Not sure if I understand correctly but something like the following?

SELECT * FROM Student ORDER BY TotalMarks DESC LIMIT 0,9
Member 10011989 19-Sep-15 5:25am    
but this will give me first 10 records strarting from 1st tuple, bt what if the 11th tuple contains value greater than retrived result !!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900