Jump to content

Next Button Alphabetically


fortara

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/215229-next-button-alphabetically/
Share on other sites

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.