soycharliente Posted January 21, 2010 Share Posted January 21, 2010 On my users.php page, I'm getting the user information based on their user id in the query: users.php?id=398457934 I'm trying to create prev/next links to move from user to user. I need to to move back and forth based on lastname alphabetically. The uid is assigned by the system and cannot be changed to assign in alphabetical order. The users are not stored in alphabetical order either. This query returns nothing in phpMyAdmin (no results, no empty set, no error): (SELECT `uid` FROM `users` WHERE (SELECT `lastname` FROM `users` WHERE `uid`<{$id} ORDER BY `uid` DESC LIMIT 1) ) UNION (SELECT `uid` FROM `users` WHERE (SELECT `lastname` FROM `user` WHERE `uid`>{$id} ORDER BY `uid` DESC LIMIT 1) ) I don't know where to go from here. It used to be a lot longer and more wrong. I've managed to think through it and eliminate things to this point. Any thoughts or help? Quote Link to comment https://forums.phpfreaks.com/topic/189371-returning-results-in-order/ Share on other sites More sharing options...
kickstart Posted January 22, 2010 Share Posted January 22, 2010 Hi Think you need something closer to:- (SELECT `uid` FROM `users` WHERE `lastname` < (SELECT lastname FROM `users` WHERE `uid` = {$id}) ORDER BY `lastname` DESC LIMIT 1 ) UNION (SELECT `uid` FROM `users` WHERE `lastname` > (SELECT lastname FROM `users` WHERE `uid` = {$id}) ORDER BY `lastname` ASC LIMIT 1 ) All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/189371-returning-results-in-order/#findComment-999829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.