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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.