Sound like a straightforward control-break (at least, that's what 
they used to call it in the COBOL days :-)  

assuming you're getting data into an assoc array called $records, 
you could stick this into your loop:  

{
        $letter = $records['LastName']{0};
        if ($prev != $letter) {
                print("<br>$letter$sep");
                $prev = $letter;
        }
        print($records['LastName'] . "<br>");
}

If you want to keep it neat, you can put it in a function, using a 
static var to keep hold of $prev. It can return an empty string when 
there is no change, or the delimiter if the letter has changed.  

Geoff.


On 19 Jan 2006 at 10:19, Jeffrey Pearson wrote:

> OK. I know I did this a LONG time ago but I don't remember how I did  
> it. Thus, my post.
> 
> I have a list of last names from a MySQL database. I need to display  
> them grouped by the first letter of their last names and insert a  
> separator on display. Similar to a phone book. So it looks like;
> 
> 
> A
> ___
> Adams
> Apple
> Army
> 
> B
> __
> Banjo
> Bank
> Bark
> 
> C
> __
> Captain
> Car
> 
> 
> 
> Is there a way without jumping through too many hoops?
> 
> Thanks for any input you can give.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> !DSPAM:43cfe677219529533614314!
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to