At 2:37 PM -0700 9/18/01, Photocon wrote:
>I have a listing of last names in a table. I would like to get MySQL
>to give me a result set of last names that began with a letter so
>that in PHP I can put them into alpha order. I don't want a set of
>all names, just those with one letter (the idea being I can then
>have one letter per page), and I don't want to "select all" from the
>whole table. Does anyone know how to do this, or am I going about it
>the wrong way?
>Conrad Hunziker III
What, you mean like:
SELECT last_name FROM tbl_name WHERE LEFT(last_name,1) = 'A'
or something? If so, you don't need to have PHP put them in order.
Just add ORDER BY last_name to the query.
If you want to know which letters last names begin with in your
table (so that you can, for example, avoid generating a page for 'X'
if no names begin with that letter), do this:
SELECT DISTINCT LEFT(last_name,1) AS letter FROM tbl_name ORDER BY letter
Paul DuBois, [EMAIL PROTECTED]
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]