creating a previous and next button
Posted: Tue May 07, 2013 6:46 pm
SOLUTION
this would be easy if i was doing it via the id number but i want to do it via two fields.
i have my databse setup with the first_name and last_name seperated. when i create a list of the names for a select i use SELECT * FROM table ORDER BY fname sname ASC.
that works fine. now i want that when ive for someone selected and ive got next to the select input i want to have a previous and next button which will look for the previous name thats less than the current one and a next name thats more.
lets say the names i have are "Adam Family, Bob Barker, Peter Parker, Peter Pipper, Thor Thunder and Zena Princess"
if peter parker is selected i want previous to say bob barker and next to say peter pipper. NOTE: their are not in that order in the database
i found this on a site for doing a previous and next search but thats doing it for only
i tried to convert it to my needs
but this didnt seem to work. i know the WHERE clause is robust but i cant figure out the right wording
Code: Select all
"SELECT CONCAT(fname,' ',sname) as meow FROM table WHERE CONCAT(fname,' ',sname) < '$getfullname' ORDER BY meow DESC LIMIT 1 "
this would be easy if i was doing it via the id number but i want to do it via two fields.
i have my databse setup with the first_name and last_name seperated. when i create a list of the names for a select i use SELECT * FROM table ORDER BY fname sname ASC.
that works fine. now i want that when ive for someone selected and ive got next to the select input i want to have a previous and next button which will look for the previous name thats less than the current one and a next name thats more.
lets say the names i have are "Adam Family, Bob Barker, Peter Parker, Peter Pipper, Thor Thunder and Zena Princess"
if peter parker is selected i want previous to say bob barker and next to say peter pipper. NOTE: their are not in that order in the database
i found this on a site for doing a previous and next search but thats doing it for only
Code: Select all
select * from mytable where id < 8 order by id desc limit 1Code: Select all
select * from table WHERE (first_name < '$firstname') AND (last_name < '$lastname') ORDER BY first_name ,last_name desc limit 1