Sometimes we have need alphabetical search or pagination. It is very much simple. How we will do it-
1. At first we will make an array with all alphabetical character.
<?php
$allAlphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
?>
2. Print/echo all alphabetical character sequentially using foreach loop
<?php
foreach($allAlphabet as $singleCharacter)
{
echo $singleCharacter;
}
?>
3. Make a link every character when echo/print character
<?php
foreach($allAlphabet as $singleCharacter)
{
//make link your code format
}
?>
4. Get singleCharacter from url
<?php
$letter = $_POST['singleCharacter'] OR $_GET['singleCharacter'] OR $this->uri->segment(’segmentNumber’);
?>
5. Make a search query and get result
<?php
$sql = “SELECT *
FROM tables
WHERE fieldName LIKE ‘$letter%’”;
?>
If you have any question, please feel free ask me!
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.