Unanswered: Create alphabetical directory in PHP off mysql database
I'm working on my first PHP/MySQL site and have laid out the site requirements, but am having trouble figuring out how to create a members' directory page, sorted alphabetically with alpha anchors at the top of the page. The data will be taken from a MySql database (which so far only has a last name field).
In other words if someone wants to see the people with last names starting with a "D", they need to be taken to the 4th section of the page. How can I determine the construction of this page?
Hope that this is not just my ignorance showing....thanks for any help,
This is almost what I'm looking for....
I'm pretty novice using php/mysql, but I seem seem to figure out out most of my problems, except for the alphabetical thing.
I hav a db filled with artists, and i need a way to have them ordered alphabetical, per page, eg ABCDEFG..etc, where the letters can be clicked and the query shows me only artists that start with the clicked letter.
Anyone here willing to help me out? this thing is driving me nuts :P
This is also pretty easy.First you would need to decide on the field that determines the sort order.(First Name or LastName).
Then perform a query, that would take out the first character of the field data.There are substring functions in mysql to do this task.You may have to give DISTINCT clause to the obtained result ; otherwise you will end with duplicate letters.
Once you have got the alphabets, display them in a loop and link them to a page, and pass the character as a query string.In that page,grab this parameter and perform a query like this.
select * from table where fieldname like '$char%'
Does this answer your query? Tell me if you find any difficulty here.