A query on the current data record and the next

A query on the current data and the next data in MySQL in by "order by" achieve, for example:

上一条:select * from aft_article where id < 10 order by id desc limit 1
下一条:select * from aft_article where id > 10 order by id limit 1

The following tp5 achieve a query on the current data and the next data, we must first get the current id, in fact, the same as with the above principles:

// get the current ID 
$ ID = INPUT ( 'ID' ); 
        
// last data 
$ PREV = DB ( 'Article This article was') -> WHERE ( 'ID', "<", $ ID ) -> Order ( "ID desc ") -> Find ();
 // next data 
$ next = DB ( 'Article This article was') -> WHERE ( 'ID',"> ", $ ID ) -> Order (" ID ") -> Find ( );

 You give id by using orderby sort and then take the first limit, the next is positive, that is, reverse Previous

 

 

Guess you like

Origin www.cnblogs.com/bushui/p/11953974.html