Re: Creating a line break between letter groupings
| From: | Tom Rogers | Date: | Thu, 20 Nov 2003 01:12:55 +0000 |
| Subject: | Re: Creating a line break between letter groupings | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-170370@lists.php.net to get a copy of this message | ||
Hi,
Thursday, November 20, 2003, 11:03:22 AM, you wrote:
DP> I'm reading a list of stores from a database and ordering them
DP> alphabetically. How would I place a line break in between each letter
DP> grouping? For example,
DP> Applebee's
DP> Aaron's Place
DP> Aardvark Store
DP> Bumblebee's
DP> Bears R' Us
DP> Big Bad Johnny's
DP> Caterpillar central
DP> Coffee time!!
DP> etc.- with the line break occuring in between each letter grouping.
DP> Any help would be greatly appreciated.
DP> --
DP> ------------------------------------------------------------
DP> http://www.phreshdesign.com
Keep track of the first letter and if it changes echo a <br>
$key = ''
//loop through results
while($result = mysql......){
$char = strtoupper(substr($row['name'],0,1));
if(empty($key){
$key = $char;//first result set key
else{
if($key != $chat){
echo '<br>';
$key = $char;
}
}
//rest of loop
}
--
regards,
Tom