mysql - Find Next Previous records with sorting -
i'd make navigation links of search result, not sure how previous , next ids in mysql?
let's say, user searching stuff , ordered year, , result set like:
id year 444 2013 333 2013 555 2013 <---- user clicks here (i.e. known id 555) 777 2012 111 2012
how previous , next ids (333, 777)?
updated answer
you can try query this, if can you.
select id tablename phones '99091505' , id = 555 order year union (select id tablename phones '99091505' , id < 555 order year desc limit 1) union (select id tablename phones '99091505' , id > 555 order year asc limit 1)
old answer
this not specific solution general idea achieve want!
at first, should save total number of rows found somewhere specific search.
so when user first time shown search result, show him first link, , keep track next 2nd link.
so user clicks next button, create query select xvy tablename abc=def order year limit 1,1
so if user on 5th search result page , clicks on next button, query like
select id tablename abc=def order year limit 5,1;
i think better programming language, not mysql query.
Comments
Post a Comment