Forum Moderators: coopster
Here is an approach though:
1. While retrieving the data from the database in your sql statement sort the data in that_field.
2. While trying to display the data, you keep on looping the data for display till you see a change in the first character of the words, like a change from A to B to C . . .
Hope this gives you a hint, but yes there can be easier ways of doing it based on what you exactly want to display.
Habtom
<?php
$input = // your sql data, assuming this is individual words in array format
$alph = array('a', 'b', 'c', ... , 'w', 'x', 'y', 'z');
foreach ($input as $word) {
for ($i=0; $i<26; $i++) {
$pattern = "%^$alph[$i]%i"; // starts with letter from alph
if (preg_match($pattern, $word, $matches) {
echo $alph[$i];
echo '<pre>';
print_r($matches);
echo '</pre>';
}
}
}
?>
[edited by: PHP_Chimp at 10:36 am (utc) on Nov. 29, 2007]