How to get the six largest values ​​out of the database? Why then this does not work and displays in the form?

555553 422154 35355353 300 1234134 123412 

Here is the code that fetches

 $query = "SELECT * FROM `DBTop` ORDER BY `col_vo` DESC LIMIT 6"; $TOP = mysql_query($query, $db) or die(mysql_error()); if(mysql_num_rows($TOP) > 5){ while($sTOP = mysql_fetch_assoc($TOP)){ echo $sTOP['col_vo'] . "<br />"; } } else { echo 'лол'; } 

    1 answer 1

    Your "col_vo" field is represented as a text (in my opinion, even varchar). The query is adequate, but the server sorts only the MySQL text fields alphabetically (the character code value), where "5555" is less for "6" and "9" is more for "1111".

    Pay attention to the first numbers (symbols): 5 55553 4 22154 3 5355353 3 00 1 234134 1 23412

    Set the field data type integer and you will be happy :)

    • Oops my space forgot about it - Vlmake