MySQL Query Limit Between Two Value

Issue

I am new in PHP and trying to get result from table between two value. I want get first row 0 to 5 numbers and so I have written query like below

$sql = "SELECT number, status, user_id 
        from number_list 
        WHERE disable=0 
        LIMIT 0,5";

But its not giving me first 5 rows. Its providing some other values. Let me know what is issue and how can I get row between two numbers ?

Thanks

Solution

You should use limit 5 for first 5 rows

 $sql = "SELECT number, status, user_id from number_list WHERE disable=0 LIMIT 5 ";

anyway when the use limit should be better use order by too .. eg

 $sql = "SELECT number, status, user_id from number_list WHERE disable=0 
   order by number LIMIT 5 ";

Answered By – ScaisEdge

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published