fortara Posted October 5, 2010 Share Posted October 5, 2010 Hello everyone. Newbie question. I have a page that pulls listings from a database by letter (a,b,c, etc) , but I would like to have a Next button, that would take people to the next letter, but can't figure out how to make that happen. I understand doing that with numbers and using the +1 for the next page, but how do you code a next button to search for the next letter? Any help would be VERY appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/215229-next-button-alphabetically/ Share on other sites More sharing options...
annihilate Posted October 5, 2010 Share Posted October 5, 2010 $az = range('a', 'z'); $current_letter = 'f'; $current_key = array_search($current_letter, $az); $next_letter = ($current_key !== false && $current_key < (count($az) - 1)) ? $az[++$current_key] : ''; echo $next_letter; // prints g Would obviously need some work to handle what happens if the current letter isn't found in the array or when the letter is z. Currently will just assign next letter to be an empty string in these circumstances. Quote Link to comment https://forums.phpfreaks.com/topic/215229-next-button-alphabetically/#findComment-1119447 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.