search

Home  >  Q&A  >  body text

How to query the 5 pieces of data starting with a specified ID in laravel5.2?

For example, there are a total of 10 pieces of data with IDs 1-10, and now I want to query the 5 pieces of data after the specified ID based on the passed ID,

For example, if the incoming id is 1, the data with id 1,2,3,4,5 will be queried.
If the id is 3, the id will be 3,4,5,6. 7 data

How to write?Thank you

ringa_leeringa_lee2754 days ago423

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 16:50:32

    Take the users table as an example:

    \DB::table('users')
        -> where('id', '>=', $id)
        -> orderBy('id')
        -> take(5)
        -> get();

    reply
    0
  • 高洛峰

    高洛峰2017-05-16 16:50:32

    where id >=1 and id <=5
    where id >=3 and id <=7

    reply
    0
  • Cancelreply